Struct offset_allocator::Allocator
source · pub struct Allocator<NI = u32>where
NI: NodeIndex,{ /* private fields */ }
Expand description
An allocator that manages a single contiguous chunk of space and hands out portions of it as requested.
Implementations§
source§impl<NI> Allocator<NI>where
NI: NodeIndex,
impl<NI> Allocator<NI>where
NI: NodeIndex,
sourcepub fn new(size: u32) -> Self
pub fn new(size: u32) -> Self
Creates a new allocator, managing a contiguous block of memory of size
units, with a default reasonable number of maximum allocations.
sourcepub fn with_max_allocs(size: u32, max_allocs: u32) -> Self
pub fn with_max_allocs(size: u32, max_allocs: u32) -> Self
Creates a new allocator, managing a contiguous block of memory of size
units, with the given number of maximum allocations.
Note that the maximum number of allocations must be less than
NodeIndex::MAX
minus one. If this restriction is violated, this
constructor will panic.
sourcepub fn allocate(&mut self, size: u32) -> Option<Allocation<NI>>
pub fn allocate(&mut self, size: u32) -> Option<Allocation<NI>>
Allocates a block of size
elements and returns its allocation.
If there’s not enough contiguous space for this allocation, returns None.
sourcepub fn free(&mut self, allocation: Allocation<NI>)
pub fn free(&mut self, allocation: Allocation<NI>)
Frees an allocation, returning the data to the heap.
If the allocation has already been freed, the behavior is unspecified. It may or may not panic. Note that, because this crate contains no unsafe code, the memory safe of the allocator itself will be uncompromised, even on double free.
sourcepub fn allocation_size(&self, allocation: Allocation<NI>) -> u32
pub fn allocation_size(&self, allocation: Allocation<NI>) -> u32
Returns the used size of an allocation.
Note that this may be larger than the size requested at allocation time, due to rounding.
sourcepub fn storage_report(&self) -> StorageReport
pub fn storage_report(&self) -> StorageReport
Returns a structure containing the amount of free space remaining, as well as the largest amount that can be allocated at once.
sourcepub fn storage_report_full(&self) -> StorageReportFull
pub fn storage_report_full(&self) -> StorageReportFull
Returns detailed information about the number of allocations in each bin.