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.

  • [UnsizedCopy], a marker trait indicating a value can be copied safely even if unsized.

  • [Thin], a marker trait indicating a pointer to a type has no metadata.

And, if the alloc_ext feature is on:

  • AllocExt, defining abstractions over Alloc’s API.

§Examples

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

Modules§

error
Errors which can occur during allocation.
ffi
FFI bindings to allocation libraries.
helpers
Helpers which tend to be useful in other libraries as well.
jemalloc
Module for jemalloc support.
marker
Marker traits.
mimalloc
Module for mimalloc support.
stats
Allocation statistic gathering and reporting.
type_props
Sized type properties as constants and property getters for pointers.
unstable_util
Small alternatives to Rust functions which are currently unstable.

Structs§

DefaultAlloc
Default allocator, delegating to the global allocator.

Traits§

Alloc
A 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.
ResizeInPlace