pub struct SlabPool<T: Copy> { /* private fields */ }Expand description
A pool of fixed-size slabs for common tensor sizes.
Pre-allocates slabs of common sizes (e.g., 64, 256, 1024, 4096 elements) and hands them out on request, recycling them when returned.
§Examples
use scivex_core::arena::SlabPool;
let pool: SlabPool<f64> = SlabPool::new();
let mut buf = pool.acquire(100); // gets a 256-element slab
assert!(buf.capacity() >= 100);
buf[0] = 42.0;
pool.release(buf);
// The next acquire of a similar size reuses the released buffer.
let buf2 = pool.acquire(100);
assert!(buf2.capacity() >= 100);Implementations§
Source§impl<T: Copy + Default> SlabPool<T>
impl<T: Copy + Default> SlabPool<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new slab pool with default size classes (64, 256, 1024, 4096, 16384, 65536).
Sourcepub fn with_sizes(sizes: &[usize]) -> Self
pub fn with_sizes(sizes: &[usize]) -> Self
Create a pool with custom size classes.
The provided sizes are sorted internally.
Sourcepub fn acquire(&self, min_size: usize) -> Vec<T>
pub fn acquire(&self, min_size: usize) -> Vec<T>
Acquire a buffer of at least min_size elements.
If a recycled slab of suitable size is available, it is returned
(zero-cleared). Otherwise a fresh Vec is allocated.
Sourcepub fn release(&self, buf: Vec<T>)
pub fn release(&self, buf: Vec<T>)
Return a buffer to the pool for reuse.
If the buffer’s capacity doesn’t match any size class it is simply dropped.
Sourcepub fn available_count(&self) -> usize
pub fn available_count(&self) -> usize
Number of available (recycled) slabs across all size classes.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for SlabPool<T>
impl<T> !RefUnwindSafe for SlabPool<T>
impl<T> Send for SlabPool<T>where
T: Send,
impl<T> !Sync for SlabPool<T>
impl<T> Unpin for SlabPool<T>where
T: Unpin,
impl<T> UnsafeUnpin for SlabPool<T>
impl<T> UnwindSafe for SlabPool<T>where
T: UnwindSafe,
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