CustomAllocator

Trait CustomAllocator 

Source
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§

Source

fn allocate(&self, size: usize, alignment: usize) -> Result<NonNull<u8>>

Allocate memory with specific alignment

Source

fn deallocate(&self, ptr: NonNull<u8>, size: usize, alignment: usize)

Deallocate previously allocated memory

Source

fn reallocate( &self, ptr: NonNull<u8>, old_size: usize, newsize: usize, alignment: usize, ) -> Result<NonNull<u8>>

Reallocate memory to a new size

Source

fn get_stats(&self) -> AllocatorStats

Get allocator statistics

Source

fn reset(&self)

Reset allocator state

Implementors§