Skip to main content

SlabPool

Struct SlabPool 

Source
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>

Source

pub fn new() -> Self

Create a new slab pool with default size classes (64, 256, 1024, 4096, 16384, 65536).

Source

pub fn with_sizes(sizes: &[usize]) -> Self

Create a pool with custom size classes.

The provided sizes are sorted internally.

Source

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.

Source

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.

Source

pub fn available_count(&self) -> usize

Number of available (recycled) slabs across all size classes.

Trait Implementations§

Source§

impl<T: Copy + Default> Default for SlabPool<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.