pub struct SlotPool { /* private fields */ }Expand description
A buffer pool with one or two fixed-slot tiers.
Allocation and deallocation are O(1) per slot. Eligible allocations first try the optional lower tier and fall back to the required upper tier when the lower tier is full.
Implementations§
Source§impl SlotPool
impl SlotPool
Sourcepub fn new(layout: SlotLayout) -> Result<Self, AllocError>
pub fn new(layout: SlotLayout) -> Result<Self, AllocError>
Create a single-tier recycling pool from exact slot placement.
Sourcepub fn new_tiered(
lower: SlotLayout,
upper: SlotLayout,
) -> Result<Self, AllocError>
pub fn new_tiered( lower: SlotLayout, upper: SlotLayout, ) -> Result<Self, AllocError>
Create a two-tier recycling pool from exact lower and upper layouts.
The lower layout must precede the upper layout without overlap, and its slot size must not exceed the upper slot size. Adjacent equal-sized layouts form one tier.
Sourcepub fn live_addrs(&self) -> Vec<u64>
pub fn live_addrs(&self) -> Vec<u64>
Return every live slot address in deterministic tier and index order.
Sourcepub fn layouts(&self) -> (Option<SlotLayout>, SlotLayout)
pub fn layouts(&self) -> (Option<SlotLayout>, SlotLayout)
Return the lower and upper tier layouts.
Sourcepub fn slot_addr(&self, index: usize) -> Option<u64>
pub fn slot_addr(&self, index: usize) -> Option<u64>
Compute the address of slot index, with lower-tier slots first.
Returns None if index >= count.
Sourcepub fn num_free_lower(&self) -> usize
pub fn num_free_lower(&self) -> usize
Total number of free slots in the lower tier.
Sourcepub fn num_free_upper(&self) -> usize
pub fn num_free_upper(&self) -> usize
Total number of free slots in the upper tier.
Sourcepub fn dealloc(&self, addr: u64) -> Result<(), AllocError>
pub fn dealloc(&self, addr: u64) -> Result<(), AllocError>
Free a previously allocated slot by address.
Sourcepub fn allocation_len(&self, addr: u64) -> Result<usize, AllocError>
pub fn allocation_len(&self, addr: u64) -> Result<usize, AllocError>
Capacity of a live allocation by its start address.
Sourcepub fn lower_slot_size(&self) -> Option<usize>
pub fn lower_slot_size(&self) -> Option<usize>
Slot size in bytes for the lower tier, if present.
Sourcepub fn upper_slot_size(&self) -> usize
pub fn upper_slot_size(&self) -> usize
Maximum slot size in bytes for the upper tier.
Sourcepub fn alloc(&self, len: usize) -> Result<Allocation, AllocError>
pub fn alloc(&self, len: usize) -> Result<Allocation, AllocError>
Allocate one slot holding at least len bytes.