Skip to main content

AllocatorCore

Trait AllocatorCore 

Source
pub unsafe trait AllocatorCore {
    // Required methods
    fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocatorError>;
    unsafe fn deallocate(&self, ptr: NonNull<[u8]>, layout: Layout);
}
Expand description

A dynamic memory allocator for use with crate::alloc::Poly.

§Safety

Implementations must ensure that if allocate succeeds, the returned slice has a length of at least layout.size() bytes and an alignment of at least layout.align(). If this cannot be satisfied, then an error must be returned.

Required Methods§

Source

fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocatorError>

Allocate space for at least layout.size() bytes aligned to at least layout.align(). Returns an error if the requested size or alignment is not possible with this allocator.

Source

unsafe fn deallocate(&self, ptr: NonNull<[u8]>, layout: Layout)

Deallocation companion to allocate.

§Safety

The caller must ensure that

  1. ptr is “currently allocated” from the allocator. See: https://doc.rust-lang.org/std/alloc/trait.Allocator.html#currently-allocated-memory
  2. ptr has the same base pointer as the slice-pointer returned from Self::allocate.
  3. layout is the same layout that was passed to Self::allocate for this pointer.

Implementors§