Expand description
A bump allocator with an explicit reset.
Programs that need alloc on a freestanding target need a
#[global_allocator], and a bump arena is the cheapest thing that
works: allocation is a pointer add, and a program that runs once and
exits never needs to free.
BumpAlloc::reset is what makes the arena re-usable. Without it a
program is single-shot per instance — the second invocation walks
off the end of the arena and the allocation fails, which surfaces as
a guest panic rather than anything legible. That matters for any
caller that invokes the same instance twice, benchmark harnesses
very much included: measuring steady-state execution means running
the same instance repeatedly.
Resetting is not free of consequences: it invalidates every live
allocation at once. It is only sound at a point where nothing from
the previous invocation is still borrowed — i.e. at an entry point,
before any work begins. bump_allocator!
generates a reset_heap() for exactly that use.
Structs§
- Bump
Alloc - A fixed-size bump arena of
Nbytes.