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.
  • PtrProps, properties getters for pointers to values.
  • [SizedProps], properties for sized types. Similar to the unstable SizedTypeProperties.

And, if the alloc_ext feature is on:

  • AllocExt, defining abstractions over Alloc’s API.
  • UnsizedCopy, a marker trait indicating a value can be copied safely even if unsized.

§Examples

let allocator = DefaultAlloc;
// Allocate 4 usizes.
let ptr: NonNull<usize> = allocator.alloc_count::<usize>(4).expect("alloc failed");
unsafe {
    for i in 0..4 {
        ptr.add(i).write(17384 * i + 8923)
    }
}
// Deallocate the block.
unsafe { allocator.dealloc_n(ptr, 4) };

Modules§

type_props

Structs§

DefaultAlloc
Default allocator, delegating to the global allocator.

Enums§

AllocError
Errors for allocation operations.

Traits§

Alloc
A minimal memory allocation interface.
AllocExt
Extension methods for the core Alloc trait, providing convenient routines to allocate, initialize, clone, copy, and deallocate sized and unsized types.
UnsizedCopy
Unsafe marker trait for types that can be copied, including unsized types such as slices.