Expand description
§memory-pool-allocator
A no_std, thread-safe, array chunk tracking-based fixed-size memory pool allocator.
§Features
- User-provided memory pool (via
*mut u8) - Chunked allocation with array-based chunk tracking
- Optional statistics and zero-on-free features
- Thread-safe via
parking_lot::Mutex
§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).
§Type Parameters
N: Total pool size in bytesM: Number of chunks to divide the pool into
§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.
§Example
#[repr(align(64))]
struct Aligned {
mem: [u8; 1024]
}
let mut aligned = Aligned { mem: [0; 1024] };
let allocator = unsafe { MemoryPoolAllocator::<1024, 64>::new(aligned.mem.as_mut_ptr()) };
let layout = Layout::from_size_align(128, 64).unwrap();
let ptr = allocator.try_allocate(layout).unwrap();
assert_eq!(ptr as usize % 64, 0);
allocator.try_deallocate(ptr).unwrap();§License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Structs§
- Memory
Pool Allocator - Array chunk tracking-based fixed-size memory pool allocator
- Pool
Stats - Pool statistics
Enums§
- Alloc
Error - Allocation errors