Skip to main content

MemoryPool

Trait MemoryPool 

Source
pub trait MemoryPool {
    // Required methods
    fn allocate(&self, size: usize, align: usize) -> Result<NonNull<u8>>;
    unsafe fn deallocate(
        &self,
        ptr: NonNull<u8>,
        size: usize,
        align: usize,
    ) -> Result<()>;
    fn capacity(&self) -> usize;
    fn used(&self) -> usize;
    unsafe fn reset(&self) -> Result<()>;

    // Provided method
    fn available(&self) -> usize { ... }
}
Expand description

Memory pool trait for unified pool interface

Required Methods§

Source

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

Allocate memory from the pool

§Errors

Returns PoolExhausted if no memory is available Returns InvalidAlignment if alignment requirements cannot be met

Source

unsafe fn deallocate( &self, ptr: NonNull<u8>, size: usize, align: usize, ) -> Result<()>

Deallocate memory back to the pool

§Safety

The pointer must have been allocated from this pool

Source

fn capacity(&self) -> usize

Get the total capacity of the pool

Source

fn used(&self) -> usize

Get the currently used bytes

Source

unsafe fn reset(&self) -> Result<()>

Reset the pool (deallocate all)

§Safety

All pointers allocated from this pool must not be used after reset

Provided Methods§

Source

fn available(&self) -> usize

Get the available bytes

Implementors§

Source§

impl<const BLOCK_SIZE: usize, const NUM_BLOCKS: usize, const BITMAP_SIZE: usize> MemoryPool for BlockPool<BLOCK_SIZE, NUM_BLOCKS, BITMAP_SIZE>

Source§

impl<const N: usize> MemoryPool for StaticPool<N>