Skip to main content

Module memory

Module memory 

Source
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 bytes more exceed the limit? Does NOT modify the counter. Use before creating large values (string repeat, range) to avoid allocating memory we’ll immediately reject.