pub trait UnderlyingAllocator {
    const INIT: Self;

    // Required methods
    unsafe fn init(&self, start: NonNull<u8>, len: usize);
    unsafe fn alloc(&self, layout: Layout) -> *mut u8;
    unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout);
}
Expand description

“Underlying Allocator”“ Trait

This trait serves to abstract over a general purpose GlobalAlloc implementation, and allows mnemos-alloc to do “the right thing” when it comes to the async wrapper types when used with any allocator.

UnderlyingAllocator::alloc() and UnderlyingAllocator::dealloc() must be implemented. UnderlyingAllocator::init() may or may not be necessary, depending on your allocator.

Features

When the “use-std” feature of this crate is active, an implementation of UnderlyingAllocator is provided for std::alloc::System.

Required Associated Constants§

source

const INIT: Self

A constant initializer of the allocator.

May or may not require a call to UnderlyingAllocator::init() before the allocator is actually ready for use.

Required Methods§

source

unsafe fn init(&self, start: NonNull<u8>, len: usize)

Initialize the allocator, if it is necessary to populate with a region of memory.

Safety

This function requires the caller to uphold the following invariants:

  • The memory region starting at start and ending at start + len may not be accessed except through pointers returned by this allocator.
  • The end of the memory region (start + len) may not exceed the physical memory available on the device.
  • The memory region must not contain memory regions used for memory-mapped IO.
source

unsafe fn alloc(&self, layout: Layout) -> *mut u8

Allocate a region of memory

Safety

The same as GlobalAlloc::alloc().

source

unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)

Deallocate a region of memory

Safety

The same as GlobalAlloc::dealloc().

Implementations on Foreign Types§

source§

impl UnderlyingAllocator for System

Available on crate feature use-std only.
source§

const INIT: Self = std::alloc::System

source§

unsafe fn init(&self, _start: NonNull<u8>, _len: usize)

source§

unsafe fn alloc(&self, layout: Layout) -> *mut u8

source§

unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)

Implementors§