snmalloc-rs
snmalloc-rs provides a wrapper for microsoft/snmalloc to make it usable as a global allocator for rust.
snmalloc is a research allocator. Its key design features are:
- Memory that is freed by the same thread that allocated it does not require any synchronising operations.
- Freeing memory in a different thread to initially allocated it, does not take any locks and instead uses a novel message passing scheme to return the memory to the original allocator, where it is recycled.
- The allocator uses large ranges of pages to reduce the amount of meta-data required.
Some old benchmark results are available in the snmalloc paper.
There are three features defined in this crate:
debug: Enable theDebugmode insnmalloc.1mib: Use the1mibchunk configuration.cache-friendly: Make the allocator more cache friendly (settingCACHE_FRIENDLY_OFFSETto64in building the library).
To use snmalloc-rs add it as a dependency:
# Cargo.toml
[]
= "0.2"
To set SnMalloc as the global allocator add this to your project:
static ALLOC: SnMalloc = SnMalloc;