pub struct FrameArena { /* private fields */ }Expand description
A per-frame bump allocator for temporary render-path allocations.
FrameArena wraps bumpalo::Bump with a focused API for the common
allocation patterns in the render pipeline: strings, slices, and
single values. All allocations are invalidated on reset(),
which should be called at frame boundaries.
§Capacity
The arena starts with an initial capacity and grows automatically when exhausted. Growth allocates new chunks from the global allocator but never moves existing allocations.
Implementations§
Source§impl FrameArena
impl FrameArena
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new arena with the given initial capacity in bytes.
§Panics
Panics if the system allocator cannot fulfill the initial allocation.
Sourcepub fn with_default_capacity() -> Self
pub fn with_default_capacity() -> Self
Create a new arena with the default capacity (256 KB).
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the arena, reclaiming all memory for reuse.
This is an O(1) operation. All previously allocated references are invalidated. The arena retains its allocated chunks for future allocations, avoiding repeated system allocator calls.
Sourcepub fn alloc_str(&self, s: &str) -> &str
pub fn alloc_str(&self, s: &str) -> &str
Allocate a string slice in the arena.
Returns a reference to the arena-allocated copy of s.
The returned reference is valid until the next reset().
Sourcepub fn alloc_slice<T: Copy>(&self, slice: &[T]) -> &[T]
pub fn alloc_slice<T: Copy>(&self, slice: &[T]) -> &[T]
Allocate a copy of a slice in the arena.
Returns a reference to the arena-allocated copy of slice.
The returned reference is valid until the next reset().
Sourcepub fn alloc_with<T, F: FnOnce() -> T>(&self, f: F) -> &mut T
pub fn alloc_with<T, F: FnOnce() -> T>(&self, f: F) -> &mut T
Allocate a single value in the arena, constructed by f.
Returns a mutable reference to the arena-allocated value.
The returned reference is valid until the next reset().
Sourcepub fn alloc<T>(&self, val: T) -> &mut T
pub fn alloc<T>(&self, val: T) -> &mut T
Allocate a single value in the arena.
Returns a mutable reference to the arena-allocated value.
The returned reference is valid until the next reset().
Sourcepub fn allocated_bytes(&self) -> usize
pub fn allocated_bytes(&self) -> usize
Returns the total bytes allocated in the arena (across all chunks).
Sourcepub fn allocated_bytes_including_metadata(&self) -> usize
pub fn allocated_bytes_including_metadata(&self) -> usize
Returns the total bytes of unused capacity in the arena.