Skip to main content

Module memory

Module memory 

Source
Expand description

Runtime memory accounting.

The accounting is intentionally explicit:

  • a buffer is charged for the bytes it stores (len), the same unit a register Str / Bytes pays on this budget;
  • spare capacity the caller allocated before handing the buffer over is not charged;
  • replacements release the old charge;
  • Drop releases the final charge;
  • failed reservations never modify the current value.

Order for overwrite (S3):

reserve(new) → release(old) → install(new)

Never install before releasing the previous charge. Peak usage during a successful replace is therefore old + new until the old charge is released — a same-size swap can fail against a tight ceiling even though the steady-state footprint would fit.

§What this does not guarantee

HeapStr / HeapBytes charge the bytes they store. Rust code that builds a String / Vec before handing it over has already allocated; spare capacity in that buffer is invisible to the budget, the same way a register Str pays str.len(). RuntimeConfig::max_runtime_bytes is therefore a runtime-managed accounting ceiling, not a global allocator sandbox.

Structs§

HeapBytes
Opaque byte buffer charged against a MemoryBudget.
HeapStr
UTF-8 heap buffer charged against a MemoryBudget.
MemoryBudget
Process- or scope-wide byte budget with atomic charge/release.
MemorySnapshot
Point-in-time view of a budget (read-only observability).

Enums§

MemoryError
Fail-closed memory reservation error.