pub struct TensorPool { /* private fields */ }Expand description
Slab-based, thread-safe buffer pool for zero-copy Arrow IPC tensor operations.
Internally maintains 8 free lists — one per power-of-two size class from
256 B to 32 MiB. All free lists are protected by individual Mutex locks
so contention is minimised.
§Thread Safety
TensorPool is Send + Sync and can be wrapped in an Arc for sharing
across threads / async tasks.
Implementations§
Source§impl TensorPool
impl TensorPool
Sourcepub fn new(config: TensorPoolConfig) -> Self
pub fn new(config: TensorPoolConfig) -> Self
Create a new TensorPool with the supplied configuration.
Sourcepub fn acquire(&self, min_bytes: usize) -> PooledBuffer
pub fn acquire(&self, min_bytes: usize) -> PooledBuffer
Acquire a buffer whose capacity is at least min_bytes.
If the corresponding free list is non-empty, a buffer is popped and
returned (incrementing total_reuses). Otherwise a fresh Vec<u8> is
allocated (incrementing total_allocs).
In both cases total_acquired is incremented.
Sourcepub fn release(&self, buf: PooledBuffer)
pub fn release(&self, buf: PooledBuffer)
Release a buffer back into the pool.
The buffer contents are cleared (length reset to 0, capacity retained)
before being added to the free list. If the free list for the buffer’s
bucket already holds max_per_bucket entries, the buffer is simply
dropped (freeing its memory).
Increments total_released in both cases. Adjusts total_bytes_pooled
by the buffer’s capacity when it is successfully pooled.
Sourcepub fn pool_depth(&self, bucket: usize) -> usize
pub fn pool_depth(&self, bucket: usize) -> usize
Return the number of free (available) buffers in the specified bucket.
§Panics
Panics in debug mode if bucket >= NUM_BUCKETS.
Sourcepub fn stats(&self) -> TensorPoolSnapshot
pub fn stats(&self) -> TensorPoolSnapshot
Capture a snapshot of the pool statistics.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for TensorPool
impl RefUnwindSafe for TensorPool
impl Send for TensorPool
impl Sync for TensorPool
impl Unpin for TensorPool
impl UnsafeUnpin for TensorPool
impl UnwindSafe for TensorPool
Blanket Implementations§
impl<T> Allocation for T
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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