pub struct OrderedPoolAllocator<'buf, T, const N: usize = { mem::size_of::<usize>() }> { /* private fields */ }
Expand description
An allocator for T
objects, with a block index of N
bytes.
If N
is 1, then blocks_capacity
will be u8::MAX
.
If N
is 2, then blocks_capacity
will be u16::MAX
.
Implementations§
Source§impl<'buf, T, const N: usize> OrderedPoolAllocator<'buf, T, N>
impl<'buf, T, const N: usize> OrderedPoolAllocator<'buf, T, N>
pub fn new_in(buf: &'buf mut [u8]) -> Self
Sourcepub unsafe fn allocate(&mut self) -> Result<NonNull<T>, AllocError>
pub unsafe fn allocate(&mut self) -> Result<NonNull<T>, AllocError>
Allocates a block and returns a pointer to the block.
This method will always prioritize reallocating an existing deallocated block over allocating a new block.
§Safety
Behavior is undefined if the returned pointer points to an uninitialized instance of T
when the allocator is dropped.
Sourcepub unsafe fn deallocate(&mut self, ptr: NonNull<T>)
pub unsafe fn deallocate(&mut self, ptr: NonNull<T>)
Deallocates the block at the specified pointer.
Side effect: swaps the virtual block indices of the specified block with the last allocated virtual block.
§Safety
Behavior is undefined if any of the following conditions are violated:
-
ptr
must point to an instance ofT
allocated by this allocator. -
ptr
must not point to an instance ofT
that has already been dropped or deallocated by this allocator.