pub struct Arena { /* private fields */ }Expand description
A single epoch’s memory arena.
Allocates by bumping a pointer forward - extremely fast. You can’t free individual allocations; instead, drop the whole arena when the epoch is no longer needed.
Thread-safe: multiple threads can allocate concurrently using atomics.
Implementations§
Source§impl Arena
impl Arena
Sourcepub fn new(epoch: EpochId) -> Result<Self, AllocError>
pub fn new(epoch: EpochId) -> Result<Self, AllocError>
Creates a new arena for the given epoch.
§Errors
Returns AllocError::OutOfMemory if the initial chunk allocation fails.
Sourcepub fn with_chunk_size(
epoch: EpochId,
chunk_size: usize,
) -> Result<Self, AllocError>
pub fn with_chunk_size( epoch: EpochId, chunk_size: usize, ) -> Result<Self, AllocError>
Creates a new arena with a custom chunk size.
§Errors
Returns AllocError::OutOfMemory if the initial chunk allocation fails.
Sourcepub fn alloc(
&self,
size: usize,
align: usize,
) -> Result<NonNull<u8>, AllocError>
pub fn alloc( &self, size: usize, align: usize, ) -> Result<NonNull<u8>, AllocError>
Allocates size bytes with the given alignment.
§Errors
Returns AllocError::OutOfMemory if a new chunk is needed and
the system allocator fails.
Sourcepub fn alloc_value<T>(&self, value: T) -> Result<&mut T, AllocError>
pub fn alloc_value<T>(&self, value: T) -> Result<&mut T, AllocError>
Sourcepub fn alloc_slice<T: Copy>(&self, values: &[T]) -> Result<&mut [T], AllocError>
pub fn alloc_slice<T: Copy>(&self, values: &[T]) -> Result<&mut [T], AllocError>
Sourcepub fn total_allocated(&self) -> usize
pub fn total_allocated(&self) -> usize
Returns the total memory allocated by this arena.
Sourcepub fn total_used(&self) -> usize
pub fn total_used(&self) -> usize
Returns the total memory used (not just allocated capacity).
Sourcepub fn stats(&self) -> ArenaStats
pub fn stats(&self) -> ArenaStats
Returns statistics about this arena.