pub trait Allocator {
// Required methods
fn malloc<T>(
&mut self,
size: usize,
align: usize,
) -> Result<NonNull<T>, KernelError>;
unsafe fn free<T>(&mut self, ptr: NonNull<T>, size: usize);
}Expand description
Allocator trait that provides a way to allocate and free memory.
Normally you don’t need to use this directly, rather use the boxed::Box type.
§Safety
Every block returned by malloc must be freed by free exactly once.
A pointer allocated by one allocator must not be freed by another allocator.
Each range added to the allocator must be valid for the whole lifetime of the allocator and must not overlap with any other range.
The lifetime of any allocation is only valid as long as the allocator is valid. (A pointer must not be used after the allocator is dropped.)
Required Methods§
fn malloc<T>( &mut self, size: usize, align: usize, ) -> Result<NonNull<T>, KernelError>
unsafe fn free<T>(&mut self, ptr: NonNull<T>, size: usize)
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl Allocator for BestFitAllocator
Implementation of the Allocator trait for BestFitAllocator.