Expand description
Thread-local persistent scratch buffer for MD2 gmegabuf / megabuf.
evalexpr Function closures can’t capture mutable state, so the backing
array lives in a thread-local RefCell<Vec<f64>> cleared from
MilkEvaluator::new() (via gmegabuf::reset). Reads at indices past the
high-water mark return 0.0 (uninitialised); writes grow the vector lazily
up to [MAX_SLOTS] so a loop(1024*1024, gmegabuf(i)=0) preset doesn’t
allocate 8 MB up-front for evaluators that never touch the buffer.
Constants§
- BUFFER 🔒
- MAX_
SLOTS - MD2’s documented cap (1 048 576 slots = 8 MB at f64). Indices outside this range silently no-op so a malformed preset can’t OOM the eval.
Functions§
- read
- Read slot
idx(clamped to[0, MAX_SLOTS)); returns 0.0 if out of range or past the current high-water mark. - reset
- Clear the buffer. Called by
MilkEvaluator::new()so each evaluator starts with fresh state on the current thread. (Within a single thread, evaluators can stomp on each other’s buffer mid-frame; in practice each preset is loaded → eval’d → dropped sequentially.) - write
- Write
valto slotidx. Grows the buffer if needed; out-of-range indices are silently ignored.