Crate memapi

Source
Expand description

memapi provides a minimal, no_std-friendly memory allocation interface for managing raw buffers, suitable for use in collections.

This crate exports:

  • Alloc, a trait defining basic allocate, deallocate, grow, and shrink operations.
  • DefaultAlloc, a zero-cost wrapper delegating to the global allocator.
  • AllocError, an enum of possible error cases.

§Examples

let allocator = DefaultAlloc;
// Make the layout for the block.
let layout = Layout::from_size_align(64, 8).unwrap();
// Allocate 64 bytes.
let ptr: NonNull<u8> = allocator.alloc(layout).expect("alloc failed");
// Deallocate the block.
unsafe { allocator.dealloc(ptr, layout) };

Structs§

DefaultAlloc
Default allocator, delegating to the global allocator.

Enums§

AllocError
Errors for allocation operations.

Traits§

Alloc
A minimal memory allocation interface.