pub struct BufferPool { /* private fields */ }Expand description
Typed buffer pool keyed by element capacity and separated by scalar type.
Each supported dtype has an independent best-fit pool. Acquired buffers are
returned without zero-initialization so kernels can avoid redundant writes
when they fully overwrite the output. Use PoolScalar::pool_acquire_zeroed
when the caller may read the buffer before writing every element.
§Examples
use tenferro_cpu_basic::buffer_pool::{BufferPool, PoolScalar};
let mut pool = BufferPool::new();
let buf = pool.acquire_zeroed::<f32>(8);
<f32 as PoolScalar>::pool_release(&mut pool, buf);
assert_eq!(pool.len(), 1);Implementations§
Source§impl BufferPool
impl BufferPool
Sourcepub fn new() -> BufferPool
pub fn new() -> BufferPool
Create an empty typed buffer pool.
§Examples
use tenferro_cpu_basic::buffer_pool::BufferPool;
let pool = BufferPool::new();
assert!(pool.is_empty());Sourcepub fn with_max_retained_capacity_bytes(
max_retained_capacity_bytes: usize,
) -> BufferPool
pub fn with_max_retained_capacity_bytes( max_retained_capacity_bytes: usize, ) -> BufferPool
Create an empty typed buffer pool with a specific retention cap.
A cap of zero disables retention. Use BufferPool::unbounded only for
diagnostics or workloads that are externally memory-limited.
§Examples
use tenferro_cpu_basic::buffer_pool::BufferPool;
let pool = BufferPool::with_max_retained_capacity_bytes(1024);
assert_eq!(pool.max_retained_capacity_bytes(), 1024);Sourcepub fn unbounded() -> BufferPool
pub fn unbounded() -> BufferPool
Create an empty typed buffer pool without a retention cap.
This preserves the historical behavior and is mainly useful for diagnostics or controlled benchmarks.
§Examples
use tenferro_cpu_basic::buffer_pool::BufferPool;
let pool = BufferPool::unbounded();
assert_eq!(pool.max_retained_capacity_bytes(), usize::MAX);Sourcepub fn max_retained_capacity_bytes(&self) -> usize
pub fn max_retained_capacity_bytes(&self) -> usize
Maximum retained typed host-buffer capacity in bytes.
§Examples
use tenferro_cpu_basic::buffer_pool::BufferPool;
let pool = BufferPool::with_max_retained_capacity_bytes(4096);
assert_eq!(pool.max_retained_capacity_bytes(), 4096);Sourcepub fn set_max_retained_capacity_bytes(
&mut self,
max_retained_capacity_bytes: usize,
)
pub fn set_max_retained_capacity_bytes( &mut self, max_retained_capacity_bytes: usize, )
Update the maximum retained typed host-buffer capacity in bytes.
Shrinking below the currently retained capacity immediately evicts retained buffers until the new cap is satisfied. A cap of zero disables retention.
§Examples
use tenferro_cpu_basic::buffer_pool::{BufferPool, PoolScalar};
let mut pool = BufferPool::with_max_retained_capacity_bytes(1024);
<f64 as PoolScalar>::pool_release(&mut pool, Vec::with_capacity(128));
pool.set_max_retained_capacity_bytes(0);
assert_eq!(pool.max_retained_capacity_bytes(), 0);
assert!(pool.is_empty());Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of retained buffers across all typed pools.
§Examples
use tenferro_cpu_basic::buffer_pool::{BufferPool, PoolScalar};
let mut pool = BufferPool::new();
<f64 as PoolScalar>::pool_release(&mut pool, vec![0.0; 2]);
assert_eq!(pool.len(), 1);Sourcepub fn retained_capacity_bytes(&self) -> usize
pub fn retained_capacity_bytes(&self) -> usize
Total retained typed host-buffer capacity in bytes.
This counts capacity that is still live in the pool. The operating system RSS may remain high after clearing the pool because the process allocator can keep freed pages for future allocations.
§Examples
use tenferro_cpu_basic::buffer_pool::{BufferPool, PoolScalar};
let mut pool = BufferPool::new();
<f64 as PoolScalar>::pool_release(&mut pool, Vec::with_capacity(2));
assert_eq!(pool.retained_capacity_bytes(), 16);Sourcepub fn stats(&self) -> BufferPoolStats
pub fn stats(&self) -> BufferPoolStats
Snapshot retained-buffer count and capacity.
§Examples
use tenferro_cpu_basic::buffer_pool::{BufferPool, PoolScalar};
let mut pool = BufferPool::new();
<f32 as PoolScalar>::pool_release(&mut pool, Vec::with_capacity(4));
let stats = pool.stats();
assert_eq!(stats.buffers, 1);
assert_eq!(stats.capacity_bytes, 16);Sourcepub fn cache_stats(&self) -> CacheStats
pub fn cache_stats(&self) -> CacheStats
Return cache-style stats for the buffers retained by this pool.
entries is the number of retained buffers, and retained_bytes is the
total retained vector capacity in bytes.
§Examples
use tenferro_cpu_basic::buffer_pool::{BufferPool, PoolScalar};
let mut pool = BufferPool::new();
<f32 as PoolScalar>::pool_release(&mut pool, Vec::with_capacity(4));
let stats = pool.cache_stats();
assert_eq!(stats.entries, 1);
assert_eq!(stats.retained_bytes, 16);Sourcepub fn acquire_with_capacity<T>(&mut self, cap: usize) -> Vec<T>where
T: PoolScalar,
pub fn acquire_with_capacity<T>(&mut self, cap: usize) -> Vec<T>where
T: PoolScalar,
Acquire a typed vector with length 0 and at least cap capacity.
Returned buffers come from the typed pool when possible and are ready for push-based population.
§Examples
use tenferro_cpu_basic::buffer_pool::BufferPool;
let mut pool = BufferPool::new();
let mut buf = pool.acquire_with_capacity::<f64>(4);
buf.extend_from_slice(&[1.0, 2.0]);
assert_eq!(buf.len(), 2);
assert!(buf.capacity() >= 4);Sourcepub fn acquire_zeroed<T>(&mut self, len: usize) -> Vec<T>where
T: PoolScalar,
pub fn acquire_zeroed<T>(&mut self, len: usize) -> Vec<T>where
T: PoolScalar,
Acquire a typed vector with length len initialized to zero.
Use this only when the caller may read elements before overwriting the
entire buffer. Full-overwrite kernels should use
crate::PooledUninitOutput to avoid the initialization cost.
§Examples
use tenferro_cpu_basic::buffer_pool::BufferPool;
let mut pool = BufferPool::new();
let buf = pool.acquire_zeroed::<f32>(3);
assert_eq!(buf, vec![0.0, 0.0, 0.0]);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether all typed pools are empty.
§Examples
use tenferro_cpu_basic::buffer_pool::BufferPool;
let pool = BufferPool::new();
assert!(pool.is_empty());Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Drop all retained buffers from the pool.
This releases the vectors owned by the pool. The process allocator may still keep freed pages mapped for reuse, so operating-system RSS is not guaranteed to fall immediately.
§Examples
use tenferro_cpu_basic::buffer_pool::{BufferPool, PoolScalar};
let mut pool = BufferPool::new();
<f64 as PoolScalar>::pool_release(&mut pool, Vec::with_capacity(8));
pool.clear();
assert!(pool.is_empty());Trait Implementations§
Source§impl Debug for BufferPool
impl Debug for BufferPool
Source§impl Default for BufferPool
impl Default for BufferPool
Source§fn default() -> BufferPool
fn default() -> BufferPool
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
impl<T, U> Imply<T> for U
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> ⓘ
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> ⓘ
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