Crate memapi

Source
Expand description

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

This crate exports:

  • Alloc: a trait defining basic allocation, deallocation, grow, and shrink operations.
  • DefaultAlloc: a zero-cost wrapper delegating to the global allocator.
  • AllocError: an enum representing allocation failure cases.
  • PtrProps: property getters for pointers to values.
  • SizedProps: properties for sized types, similar to the unstable, hidden SizedTypeProperties.
  • VarSized: a marker trait for types with usize metadata.
  • UnsizedCopy: a marker trait for safe copying of unsized values.
  • Thin: a marker trait for pointers without metadata.

§Features

  • alloc_ext: Adds the AllocExt trait for ergonomic allocator abstractions.

  • alloc_slice: Provides slice-based extensions:

  • stats: Collection of allocation statistics utilities:

    • [StatsLogger], a thread-safe logger for allocation events.
    • [Stats], an allocator wrapper that logs operations.
    • [AllocRes], [AllocStat], [MemoryRegion], [ResizeMemRegions], [AllocKind] types.
    • (With std) Several default logger implementations.
  • external_alloc: FFI helpers for external allocators.

  • jemalloc: Provides [Jemalloc], a ZST Alloc implementation using Jemallocator.

  • mimalloc: Provides [MiMalloc], a ZST Alloc implementation using MiMalloc.

  • nightly: Enables using the unstable allocator_api.

  • metadata, clone_to_uninit, specialization, sized_hierarchy: Enable using the nightly Rust feature of the same name.

  • extra_const: Enables additional const methods (MSRV ≥ 1.61.0).

  • c_str: Implements UnsizedCopy for core::ffi::CStr (MSRV ≥ 1.64.0).

  • extra_extra_const: Further expands const support (MSRV ≥ 1.83.0).

All other features are supersets of existing ones.

Modules§

error
Errors that can occur during allocation.
ffi
FFI bindings to allocation libraries.
helpers
Helpers that 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 that are unstable as of the most recent release.

Macros§

atomic_total_ops
Helper macro to implement the default atomic total operations for a StatsLogger.

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.
AllocSlice
Slice-specific extension methods for Alloc, providing convenient functions for slice allocator operations.
AllocSliceExt
Slice-specific extension methods for AllocExt, providing extended convenient functions for slice allocator operations.
ResizeInPlace
Extension trait for Alloc which provides interfaces to reallocate in-place.