pub trait CustomAllocator:
Send
+ Sync
+ Debug {
// Required methods
fn allocate(&self, size: usize, alignment: usize) -> Result<NonNull<u8>>;
fn deallocate(&self, ptr: NonNull<u8>, size: usize, alignment: usize);
fn reallocate(
&self,
ptr: NonNull<u8>,
old_size: usize,
newsize: usize,
alignment: usize,
) -> Result<NonNull<u8>>;
fn get_stats(&self) -> AllocatorStats;
fn reset(&self);
}Expand description
Custom allocator trait for different allocation strategies
Required Methods§
Sourcefn allocate(&self, size: usize, alignment: usize) -> Result<NonNull<u8>>
fn allocate(&self, size: usize, alignment: usize) -> Result<NonNull<u8>>
Allocate memory with specific alignment
Sourcefn deallocate(&self, ptr: NonNull<u8>, size: usize, alignment: usize)
fn deallocate(&self, ptr: NonNull<u8>, size: usize, alignment: usize)
Deallocate previously allocated memory
Sourcefn reallocate(
&self,
ptr: NonNull<u8>,
old_size: usize,
newsize: usize,
alignment: usize,
) -> Result<NonNull<u8>>
fn reallocate( &self, ptr: NonNull<u8>, old_size: usize, newsize: usize, alignment: usize, ) -> Result<NonNull<u8>>
Reallocate memory to a new size
Sourcefn get_stats(&self) -> AllocatorStats
fn get_stats(&self) -> AllocatorStats
Get allocator statistics