pub struct BestFitAllocator { /* private fields */ }Expand description
This is an allocator implementation that uses the best fit strategy. That does mean, when we allocate a block, we try to find the smallest block that fits the requested size. Blocks are stored in a singly linked list. The important part is that the linked list is stored in-line with the memory blocks. This means that every block has a header that contains the size of the block and a pointer to the next block.
Implementations§
Source§impl BestFitAllocator
Implementation of the BestFitAllocator.
impl BestFitAllocator
Implementation of the BestFitAllocator.
pub const MIN_RANGE_SIZE: usize = 17usize
Sourcepub unsafe fn add_range(
&mut self,
range: Range<usize>,
) -> Result<(), KernelError>
pub unsafe fn add_range( &mut self, range: Range<usize>, ) -> Result<(), KernelError>
Adds a range of memory to the allocator.
range - The range of memory to add.
Returns Ok(()) if the range was added successfully, otherwise an error.
§Safety
The range must be valid, 128bit aligned and must not overlapping with any other current or future range.
The range must also be at least as large as MIN_RANGE_SIZE.
Also the range must stay valid, for the whole lifetime of the allocator. Also the lifetime of any allocation is only valid as long as the allocator is valid.
Trait Implementations§
Source§impl Allocator for BestFitAllocator
Implementation of the Allocator trait for BestFitAllocator.
impl Allocator for BestFitAllocator
Implementation of the Allocator trait for BestFitAllocator.
Source§fn malloc<T>(
&mut self,
size: usize,
align: usize,
) -> Result<NonNull<T>, KernelError>
fn malloc<T>( &mut self, size: usize, align: usize, ) -> Result<NonNull<T>, KernelError>
Allocates a block of memory with the given size and alignment. Note: This function will always yield an invalid align for align > 128bit.
size - The size of the block.
align - The alignment of the block.
Returns the user pointer to the block if successful, otherwise an error.