pub struct BinnedAllocator {
pub alloc_count: usize,
pub free_count: usize,
/* private fields */
}Expand description
Deterministic binned allocator with LIFO free lists.
All memory is backed by a single contiguous Vec<u8> that grows
monotonically. No memory is ever returned to the OS during execution.
Fields§
§alloc_count: usizeStats: total allocations.
free_count: usizeStats: total frees.
Implementations§
Source§impl BinnedAllocator
impl BinnedAllocator
Sourcepub fn alloc(&mut self, size: usize) -> usize
pub fn alloc(&mut self, size: usize) -> usize
Allocate a block of at least size bytes. Returns a block index.
If a free block of the right size class exists, it is reused (LIFO). Otherwise, a new block is carved from the backing storage.
Sourcepub fn free(&mut self, block_idx: usize)
pub fn free(&mut self, block_idx: usize)
Free a block, returning it to the appropriate bin’s free list.
Sourcepub fn get_mut(&mut self, block_idx: usize) -> Option<&mut [u8]>
pub fn get_mut(&mut self, block_idx: usize) -> Option<&mut [u8]>
Get a mutable slice to the block’s memory.
Sourcepub fn live_count(&self) -> usize
pub fn live_count(&self) -> usize
Number of blocks currently in use.
Sourcepub fn total_blocks(&self) -> usize
pub fn total_blocks(&self) -> usize
Total blocks ever allocated.
Sourcepub fn storage_bytes(&self) -> usize
pub fn storage_bytes(&self) -> usize
Total backing storage in bytes (never shrinks).
Sourcepub fn free_block_count(&self) -> usize
pub fn free_block_count(&self) -> usize
Number of free blocks across all bins.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BinnedAllocator
impl RefUnwindSafe for BinnedAllocator
impl Send for BinnedAllocator
impl Sync for BinnedAllocator
impl Unpin for BinnedAllocator
impl UnsafeUnpin for BinnedAllocator
impl UnwindSafe for BinnedAllocator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more