memapi 0.15.2

A no_std-friendly memory allocation interface for raw buffers, with improved error reporting.
Documentation

memapi

crates.io docs.rs

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

MSRV: 1.56

MSRV with extra_const feature: 1.61

Mimalloc/Jemalloc MSRV: 1.63

MSRV with c_str feature: 1.64

MSRV with extra_extra_const feature: 1.83


Features

Features

  • Allocation primitives: allocation, deallocation, grow/shrink, and realloc operations
  • Allocation statistics (feature: stats)
  • Allocator API support on nightly (feature: nightly)
    • Clone/Copy specialization for performance and ease of use (feature: specialization)
    • CloneToUninit usage in some functions (feature: clone_to_uninit)
    • Pointer metadata usage in some functions (feature: metadata)
    • Sized hierarchy support (feature: sized_hierarchy)
  • C-style string support (feature: c_str) (MSRV: 1.64)
  • Constants: extra (feature: extra_const) (MSRV: 1.61)
  • Constants: even more (feature: extra_extra_const) (MSRV: 1.83)
  • Error reporting via AllocError
  • External allocator support (MSRV: 1.63)
    • jemalloc (feature: jemalloc)
    • mimalloc (feature: mimalloc)
  • Fallback implementation for stable Rust
  • Low-cost wrapper over the global allocator
  • no_std compatible
  • Resize-in-place extension methods (feature: resize_in_place)
  • Basic extension methods (feature: alloc_ext)
  • Slice-focused extension methods (feature: alloc_slice)
  • std support (feature: std)
  • Unstable utilities (feature: unstable_util)

Installation

Add to your Cargo.toml:

[dependencies]
memapi = "0.15.0"

Or, the recommended way:

[features]
allocator_api = ["memapi/nightly"]

[dependencies]
memapi = "0.15.0"

Benchmarks

Benchmark Base (ns) Crate (ns) Ratio Δ vs base
alloc 4.2217 4.3979 1.0417× 4.17% slower
alloc_default 3.9590 4.4648 1.1277× 12.77% slower
alloc_write 7.5617 4.2021 0.5557× 44.43% faster
alloc_filled_1k 23.2630 28.5900 1.2288× 22.88% slower
alloc_patterned_2k 840.0900 836.9500 0.9963× 0.37% faster
grow_filled_1k_to_4k 104.9400 93.9140 0.8950× 10.50% faster
realloc_filled_4k_to_1k 81.0100 72.2300 0.8918× 10.82% faster
dealloc_typed 4.1694 4.5512 1.0916× 9.16% slower
zero_and_dealloc_8k 102.8900 151.5100 1.4727× 47.27% slower

Notes

  • Numbers are medians reported by Criterion as can be seen in bench.rs.
  • Ratios < 1.0 mean the crate is faster than the base; > 1.0 means slower.
  • Any faster results are most likely error. I tried to use black_box everywhere to minimize optimizer tomfoolery, but this is inevitable.

No-Std Support

This crate works without the Rust standard library. It relies on alloc from the core distribution.


Documentation


License

Licensed under Apache-2.0 OR MIT. See LICENSE-APACHE and LICENSE-MIT.