pub struct FixedSizeAllocator<const S: usize, const N: usize> { /* private fields */ }
Implementations§
Source§impl<const S: usize, const N: usize> FixedSizeAllocator<S, N>
impl<const S: usize, const N: usize> FixedSizeAllocator<S, N>
Sourcepub unsafe fn new_unpinned(zero_initialized: bool) -> Self
pub unsafe fn new_unpinned(zero_initialized: bool) -> Self
Construct a new fixed-size allocator on the stack and return it.
Optionally, you can initialize the heap with 0
bytes by setting the zero_initialized
flag. !This doesn’t mean that the allocator is initialized!
The returned allocator struct must immediately be pinned via pin!()
. Using an unpinned allocator created on the stack is undefined behavior.
This function is marked as unsafe because it’s the programmer’s responsibility to correctly instantiate and pin an allocator on the stack.
Sourcepub fn new(zero_initialized: bool) -> Pin<Box<Self>>
pub fn new(zero_initialized: bool) -> Pin<Box<Self>>
Create a new fixed-size allocator on the heap using the standard system allocator.
Optionally, you can initialize the heap with 0
bytes by setting the zero_initialized
flag.
Note that the returned allocator is pinned, meaning it cannot be moved once it’s created. This is why a Pin<Box<>> is returned instead.
Sourcepub const fn block_count(&self) -> usize
pub const fn block_count(&self) -> usize
Return the total number of memory blocks.
Sourcepub const fn block_size(&self) -> usize
pub const fn block_size(&self) -> usize
Return the size of a memory block.
Sourcepub const fn total_free(&self) -> usize
pub const fn total_free(&self) -> usize
Return the total amount of free memory in bytes.
Sourcepub const fn total_allocated(&self) -> usize
pub const fn total_allocated(&self) -> usize
Return the total amount of memory allocated in bytes.
Sourcepub fn free_blocks(&self) -> usize
pub fn free_blocks(&self) -> usize
Return how many blocks are free.
Sourcepub fn allocated_blocks(&self) -> usize
pub fn allocated_blocks(&self) -> usize
Return how many blocks are allocated (not free).
pub unsafe fn alloc_untyped(self: Pin<&mut Self>) -> Option<NonNull<u8>>
Sourcepub fn alloc<T>(self: Pin<&mut Self>) -> Option<NonNull<T>>
pub fn alloc<T>(self: Pin<&mut Self>) -> Option<NonNull<T>>
Try to allocate a memory block of that fits T
, where T
is S
-sized.
Sourcepub fn free_nonnull<T>(
self: Pin<&mut Self>,
ptr: NonNull<T>,
) -> Result<(), FreeError>
pub fn free_nonnull<T>( self: Pin<&mut Self>, ptr: NonNull<T>, ) -> Result<(), FreeError>
Free the given non-null pointer. Note that the pointer must be aligned to the block’s start address.