pub struct RecyclePool { /* private fields */ }Expand description
A recycling buffer provider with fixed-size slots.
Holds a fixed set of equal-sized buffer addresses in a free list. Alloc and
dealloc are O(1). It is intended for bounded scatter/gather descriptor
segments that are pre-allocated and recycled after use:
alloc_sg splits a logical payload into
ceil(total_len / slot_size) fixed-size segments.
Implementations§
Source§impl RecyclePool
impl RecyclePool
Sourcepub fn new(
base_addr: u64,
region_len: usize,
slot_size: usize,
) -> Result<Self, AllocError>
pub fn new( base_addr: u64, region_len: usize, slot_size: usize, ) -> Result<Self, AllocError>
Create a recycling pool of slot_size-byte slots over a fixed region.
The base address is aligned up to slot_size; the slot count is based
on the remaining usable region after alignment.
Sourcepub fn restore_allocated(&self, allocated: &[u64]) -> Result<(), AllocError>
pub fn restore_allocated(&self, allocated: &[u64]) -> Result<(), AllocError>
Rebuild pool state so that every address in allocated is removed from
the free list, matching externally known inflight state.
Sourcepub fn slot_addr(&self, index: usize) -> Option<u64>
pub fn slot_addr(&self, index: usize) -> Option<u64>
Compute the address of slot index.
Returns None if index >= count.
Sourcepub fn dealloc_addr(&self, addr: u64) -> Result<(), AllocError>
pub fn dealloc_addr(&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.
Trait Implementations§
Source§impl BufferProvider for RecyclePool
impl BufferProvider for RecyclePool
Source§fn max_alloc_len(&self) -> usize
fn max_alloc_len(&self) -> usize
Source§fn alloc(&self, len: usize) -> Result<Allocation, AllocError>
fn alloc(&self, len: usize) -> Result<Allocation, AllocError>
len bytes.Source§fn dealloc(&self, addr: u64) -> Result<(), AllocError>
fn dealloc(&self, addr: u64) -> Result<(), AllocError>
Source§fn alloc_sg(
&self,
total_len: usize,
) -> Result<SmallVec<[Allocation; 4]>, AllocError>
fn alloc_sg( &self, total_len: usize, ) -> Result<SmallVec<[Allocation; 4]>, AllocError>
total_len bytes.Source§impl Clone for RecyclePool
impl Clone for RecyclePool
Source§fn clone(&self) -> RecyclePool
fn clone(&self) -> RecyclePool
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more