Skip to main content

Module pool

Module pool 

Source
Expand description

Fixed-size object pool allocator.

A pool allocator pre-allocates a contiguous slab of equal-sized blocks and maintains a lock-free free-list over them. Allocation pops one block from the free-list; deallocation pushes it back.

§Characteristics

PropertyValue
Allocation / deallocation costO(1), typically a single CAS
FragmentationZero (fixed-size blocks)
Thread safetyLock-free (AtomicPtr CAS loop)
Max allocation sizeblock_layout.size()
Individual deallocation✅ Supported

§Example

let pool = PoolAllocator::typed::<[u8; 64]>(&sys, 128).unwrap();
let ptr  = unsafe { pool.alloc(Layout::new::<[u8; 64]>()) }.unwrap();
// ... use memory ...
unsafe { pool.dealloc(ptr, Layout::new::<[u8; 64]>()) };

Structs§

PoolAllocator
A lock-free, fixed-size block allocator backed by a single pre-allocated slab.