memapi 0.3.4

A minimal, no_std-friendly memory allocation interface for raw buffers, with some error handling.
Documentation

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

# use memapi::{Alloc, DefaultAlloc, AllocError};
# use core::alloc::Layout;
# use core::ptr::NonNull;

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) };