Expand description
A threadsafe, lock-free bucket Allocator which partitions the provided memory into
buckets of equal size with a given alignment.
The memory chunks cannot be resized or greater than the maximum bucket size.
§Example
use iceoryx2_bb_memory::pool_allocator::*;
const BUCKET_SIZE: usize = 128;
const BUCKET_ALIGNMENT: usize = 8;
const MEMORY_SIZE: usize = 1024;
const MAX_NUMBER_OF_BUCKETS: usize = 512;
let mut memory: [u8; MEMORY_SIZE] = [0; MEMORY_SIZE];
let mut allocator = FixedSizePoolAllocator::<MAX_NUMBER_OF_BUCKETS>
::new(unsafe{ Layout::from_size_align_unchecked(BUCKET_SIZE,
BUCKET_ALIGNMENT) }, NonNull::new(memory.as_mut_ptr()).unwrap(), MEMORY_SIZE );
let mut memory = allocator.allocate(unsafe{Layout::from_size_align_unchecked(48, 4)})
.expect("failed to allocate");
let mut grown_memory = unsafe { allocator.grow_zeroed(
NonNull::new(memory.as_mut().as_mut_ptr()).unwrap(),
Layout::from_size_align_unchecked(48, 4),
Layout::from_size_align_unchecked(64, 4)
).expect("failed to grow memory")};
let mut shrink_memory = unsafe { allocator.shrink(
NonNull::new(grown_memory.as_mut().as_mut_ptr()).unwrap(),
Layout::from_size_align_unchecked(64, 4),
Layout::from_size_align_unchecked(32, 4)
).expect("failed to shrink memory")};
unsafe{ allocator.deallocate(NonNull::new(shrink_memory.as_mut().as_mut_ptr()).unwrap(),
Layout::from_size_align_unchecked(32, 4))};Structs§
- Fixed
Size Pool Allocator - Layout
- Layout of a block of memory.
- NonNull
*mut Tbut non-zero and covariant.- Pool
Allocator
Enums§
- Allocation
Error - Failures caused by
BaseAllocator::allocate()orBaseAllocator::allocate_zeroed(). - Allocation
Grow Error - Failures caused by
Allocator::grow()orAllocator::grow_zeroed(). - Allocation
Shrink Error - Failures caused by
Allocator::shrink().
Traits§
- Allocator
- Allocator with grow and shrink features.
- Base
Allocator - The most minimalistic requirement for an allocator