Struct simple_chunk_allocator::ChunkAllocator
source · [−]pub struct ChunkAllocator<'a, const CHUNK_SIZE: usize = DEFAULT_CHUNK_SIZE> { /* private fields */ }
Expand description
Low-level chunk allocator that operates on the provided backing memory. Allocates memory with a variant of the strategies next-fit and best-fit.
The default chunk size is DEFAULT_CHUNK_SIZE
. A large chunk size has the negative impact
that small allocations will consume at least one chunk. A small chunk size has the negative
impact that the allocation may take slightly longer.
Implementations
sourceimpl<'a, const CHUNK_SIZE: usize> ChunkAllocator<'a, CHUNK_SIZE>
impl<'a, const CHUNK_SIZE: usize> ChunkAllocator<'a, CHUNK_SIZE>
sourcepub const fn chunk_size(&self) -> usize
pub const fn chunk_size(&self) -> usize
Returns the used chunk size.
sourcepub const fn new(
heap: &'a mut [u8],
bitmap: &'a mut [u8]
) -> Result<Self, ChunkAllocatorError>
pub const fn new(
heap: &'a mut [u8],
bitmap: &'a mut [u8]
) -> Result<Self, ChunkAllocatorError>
Creates a new allocator object. Verifies that the provided memory has the correct properties. Zeroes the bitmap.
- heap length must be a multiple of
CHUNK_SIZE
- the heap must be not empty
- the bitmap must match the number of chunks
It is recommended that the heap and the bitmap both start at page-aligned addresses for better performance and to enable a faster search for correctly aligned addresses.
sourcepub const fn chunk_count(&self) -> usize
pub const fn chunk_count(&self) -> usize
Returns number of chunks.
pub fn allocate(&mut self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
Trait Implementations
Auto Trait Implementations
impl<'a, const CHUNK_SIZE: usize = DEFAULT_CHUNK_SIZE> !RefUnwindSafe for ChunkAllocator<'a, CHUNK_SIZE>
impl<'a, const CHUNK_SIZE: usize> Send for ChunkAllocator<'a, CHUNK_SIZE>
impl<'a, const CHUNK_SIZE: usize = DEFAULT_CHUNK_SIZE> !Sync for ChunkAllocator<'a, CHUNK_SIZE>
impl<'a, const CHUNK_SIZE: usize> Unpin for ChunkAllocator<'a, CHUNK_SIZE>
impl<'a, const CHUNK_SIZE: usize = DEFAULT_CHUNK_SIZE> !UnwindSafe for ChunkAllocator<'a, CHUNK_SIZE>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more