Expand description
Memory tracking for Bop script execution.
By default, uses thread-local counters so tracking is zero-cost and perfectly isolated between concurrent executions.
With no_std, uses global statics. This is safe for single-threaded
environments (e.g., wasm) but is NOT thread-safe.
Tracking happens at the Value layer: Clone tracks new allocations, Drop tracks
frees. The evaluator only needs to call bop_memory_init() at the start and
check bop_memory_exceeded() in tick().
Functions§
- bop_
alloc - Track a new heap allocation. Does not check the limit. Called by Value’s Clone impl and constructor helpers.
- bop_
dealloc - Track a deallocation. Called by Value’s Drop impl.
- bop_
memory_ exceeded - Returns true if current usage exceeds the limit.
Checked in
tick()to catch allocations from clones. - bop_
memory_ init - Reset the counter and set the limit for this simulation.
- bop_
would_ exceed - Pre-flight check: would allocating
bytesmore exceed the limit? Does NOT modify the counter. Use before creating large values (string repeat, range) to avoid allocating memory we’ll immediately reject.