pub struct ArenaAllocator<S: MemoryDescriptor> { /* private fields */ }Expand description
Arena allocator backed by an instance of a MemoryDescriptor object.
This struct wraps an Allocator from the offset_allocator crate,
and provides methods for allocating memory from the storage.
The allocator is thread-safe, and the storage is shared between the allocator and the buffers.
Implementations§
Source§impl<S: MemoryDescriptor> ArenaAllocator<S>
impl<S: MemoryDescriptor> ArenaAllocator<S>
Sourcepub fn new(storage: S, page_size: usize) -> Result<Self, ArenaError>
pub fn new(storage: S, page_size: usize) -> Result<Self, ArenaError>
Create a new ArenaAllocator from a MemoryDescriptor object and a page size.
The page size must be a power of two.
The allocator will divide the storage into pages and allocations will consist of a set of contiguous pages whose aggregate size is greater than or equal to the requested size.
The allocator is thread-safe, and the storage is shared between the allocator and the buffers.
Sourcepub fn allocate(&self, size: usize) -> Result<ArenaBuffer<S>, ArenaError>
pub fn allocate(&self, size: usize) -> Result<ArenaBuffer<S>, ArenaError>
Allocates a new ArenaBuffer of the given size from this allocator.
The actual allocation may consume more pages than strictly needed due to
page-size rounding. Returns ArenaError::AllocationFailed if there are
not enough contiguous pages available.
Trait Implementations§
Source§impl<S: Clone + MemoryDescriptor> Clone for ArenaAllocator<S>
impl<S: Clone + MemoryDescriptor> Clone for ArenaAllocator<S>
Source§fn clone(&self) -> ArenaAllocator<S>
fn clone(&self) -> ArenaAllocator<S>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more