pub struct BufferPool {
pub pools: HashMap<usize, Vec<Vec<f64>>>,
pub cap_per_bucket: usize,
}Expand description
Pool of reusable Vec<f64> allocations, bucketed by capacity (power of two).
This is used by the CPU-shadow (stub) path to avoid repeated heap allocation when the same buffer sizes are recycled across simulation steps.
Fields§
§pools: HashMap<usize, Vec<Vec<f64>>>Map from power-of-two bucket size → list of free buffers.
cap_per_bucket: usizeMaximum number of free buffers to retain per bucket before dropping.
Implementations§
Source§impl BufferPool
impl BufferPool
Sourcepub fn alloc(&mut self, len: usize) -> Vec<f64>
pub fn alloc(&mut self, len: usize) -> Vec<f64>
Allocate a buffer of at least len elements.
If a free buffer of the correct power-of-two bucket size exists it is returned directly (contents may be stale); otherwise a fresh zero-filled allocation is made.
Sourcepub fn free(&mut self, len: usize, buf: Vec<f64>)
pub fn free(&mut self, len: usize, buf: Vec<f64>)
Return a buffer to the pool for future reuse.
If the pool for this bucket is already at capacity, the buffer is silently dropped (deallocated).
Sourcepub fn total_free(&self) -> usize
pub fn total_free(&self) -> usize
Return the number of free buffers currently held by the pool.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BufferPool
impl RefUnwindSafe for BufferPool
impl Send for BufferPool
impl Sync for BufferPool
impl Unpin for BufferPool
impl UnsafeUnpin for BufferPool
impl UnwindSafe for BufferPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more