pub struct Arena { /* private fields */ }Expand description
A simple bump allocator for temporary allocations.
The arena pre-allocates a contiguous block of memory and hands out slices from it via bump pointer allocation. When the frame is complete, the arena is reset (O(1)) and the memory is reused.
Implementations§
Source§impl Arena
impl Arena
Sourcepub fn with_default_size() -> Self
pub fn with_default_size() -> Self
Create a new arena with the default size (64KB).
Sourcepub fn reset(&self)
pub fn reset(&self)
Reset the arena for reuse.
This is an O(1) operation - it just resets the bump pointer. The memory contents are not cleared.
Sourcepub fn alloc_slice(&self, len: usize) -> Option<&mut [u8]>
pub fn alloc_slice(&self, len: usize) -> Option<&mut [u8]>
Allocate a mutable slice of bytes.
Returns None if there’s not enough space in the arena.
SAFETY: This returns a mutable reference from a shared reference, which is safe
because we use interior mutability (Cell) to track the allocation position,
ensuring each region is only handed out once.
Sourcepub fn alloc_slice_zeroed(&self, len: usize) -> Option<&mut [u8]>
pub fn alloc_slice_zeroed(&self, len: usize) -> Option<&mut [u8]>
Allocate a mutable slice of bytes, zeroed.
Returns None if there’s not enough space in the arena.
Sourcepub fn alloc_vec(&self, initial_capacity: usize) -> Option<ArenaVec<'_>>
pub fn alloc_vec(&self, initial_capacity: usize) -> Option<ArenaVec<'_>>
Allocate a Vec-like buffer backed by the arena.
Returns an ArenaVec that can grow up to the remaining capacity.
Sourcepub fn peak_usage(&self) -> usize
pub fn peak_usage(&self) -> usize
Get the peak usage (highest watermark since creation).