memory-pool-allocator-1.0.1 has been yanked.
memory-pool-allocator
A fixed-size, thread-safe memory pool allocator for Rust, supporting custom chunk sizes and efficient allocation/deallocation. Made with the help of AI such as Claude and Copilot.
Features
- No_std compatible
- Thread-safe via
parking_lot::Mutex - Dual-licensed (Apache-2.0 OR MIT)
- Customizable pool size and chunk count via const generics
- Fast allocation and deallocation for fixed-size blocks
- Usage statistics
- User-provided memory pool (via
rust *mut u8) - Default features:
zero-on-free,zero-on-dropandstatistics.
Usage
Add to your Cargo.toml:
[]
= "1.0"
Or, if you do not want statistics and zeroing, add:
[]
= { = "1.0", = false }
Example:
use MemoryPoolAllocator;
use Layout;
let mut aligned = Aligned ;
let allocator = unsafe ;
let layout = from_size_align.unwrap;
let ptr = allocator.try_allocate.unwrap;
assert_eq!;
allocator.try_deallocate.unwrap;
Safety
- The user must provide a pointer to a memory region of at least
Nbytes, aligned to the maximum alignment required by allocations. - The allocator does not manage the lifetime of the memory pool; the user is responsible for ensuring it is valid for the allocator's lifetime.
- If the pool is not sufficiently aligned, allocations with higher alignment requirements may fail or result in undefined behavior.
N(total bytes) must be exactly divisible byM(number of chunks).
Default Features
- zero-on-free: Zeroes memory of each allocation when it is deallocated.
- zero-on-drop: Zeroes the entire memory pool when the allocator is dropped.
- statistics: Tracks allocation and deallocation statistics (number of allocated chunks, allocation/deallocation errors).
Optional Feature
- debug: Adds assertions of pool consistency for debug builds.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.