Trait mnemos_alloc::heap::UnderlyingAllocator
source · 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§
sourceconst INIT: Self
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§
sourceunsafe fn init(&self, start: NonNull<u8>, len: usize)
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 atstart + 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.
Object Safety§
Implementations on Foreign Types§
source§impl UnderlyingAllocator for System
Available on crate feature use-std
only.
impl UnderlyingAllocator for System
use-std
only.