Packages
·
v0.0.13
static-arena
A bump-pointer arena whose buffer lives entirely on the stack (or in static mut storage). Zero malloc, zero free, so it composes with the #[no_alloc] real-time contract.
Because C+ does not yet have const-generic struct parameters, it ships two fixed shapes: StaticArena16K (16 KiB) and StaticArena64K (64 KiB). The 16K shape has the full surface (alloc_bytes, alloc_bytes_aligned, alloc_zeroed_bytes, alloc_str, reset); the 64K shape is the same minus alloc_str and alloc_zeroed_bytes.
import "static-arena/static-arena" as sa;
let mut a: sa::StaticArena16K = sa::StaticArena16K::new();
guard let option::Option::Some(p) = a.alloc_bytes_aligned(64 as usize, 8 as usize) else {
return 1; // OOM
};
// ... use p ...
a.reset(); // recover full capacity, reuse
The stack size ceiling is roughly 128 KiB; for larger arenas, allocate in static mut and reference by pointer, or use the heap-backed arena.