pub struct BufferPool<T> { /* private fields */ }Expand description
A pool of reusable Vec<T> buffers that avoids repeated allocation on
hot compute paths: get() hands out a cleared buffer, put() returns it.
Implementations§
Source§impl<T> BufferPool<T>
impl<T> BufferPool<T>
Sourcepub fn new(max_size: usize) -> Self
pub fn new(max_size: usize) -> Self
Creates a new buffer pool with the given maximum number of cached buffers and a default byte-capacity budget of 64 MiB.
Sourcepub fn with_max_bytes(max_size: usize, max_pool_bytes: usize) -> Self
pub fn with_max_bytes(max_size: usize, max_pool_bytes: usize) -> Self
Creates a buffer pool with an explicit byte-capacity budget.
Sourcepub fn pooled_bytes(&self) -> usize
pub fn pooled_bytes(&self) -> usize
Returns the total byte capacity currently held by pooled buffers.
Sourcepub fn get(&self, min_capacity: usize) -> Vec<T>
pub fn get(&self, min_capacity: usize) -> Vec<T>
Gets a buffer from the pool or allocates a new one.
The returned buffer is empty but may have pre-allocated capacity from
a previous use. If min_capacity is specified, the buffer is guaranteed
to have at least that capacity.
Auto Trait Implementations§
impl<T> !Freeze for BufferPool<T>
impl<T> !RefUnwindSafe for BufferPool<T>
impl<T> Send for BufferPool<T>
impl<T> Sync for BufferPool<T>
impl<T> Unpin for BufferPool<T>
impl<T> UnsafeUnpin for BufferPool<T>
impl<T> UnwindSafe for BufferPool<T>
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
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> ⓘ
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