pub struct BufferPool { /* private fields */ }Expand description
A pool of reusable, aligned buffers.
Buffers are organized into power-of-two size classes. When a buffer is requested, the smallest size class that fits is used. Buffers are automatically returned to the pool when dropped.
§Alignment
Buffer alignment is guaranteed only at the base pointer (when cursor == 0).
After calling Buf::advance(), the pointer returned by as_mut_ptr() may
no longer be aligned. For direct I/O operations that require alignment,
do not advance the buffer before use.
Implementations§
Source§impl BufferPool
impl BufferPool
Sourcepub fn alloc(&self, capacity: usize) -> IoBufMut
pub fn alloc(&self, capacity: usize) -> IoBufMut
Allocates a buffer with the given capacity.
The returned buffer has len() == 0 and capacity() >= capacity,
matching the semantics of IoBufMut::with_capacity and
BytesMut::with_capacity. Use put_slice or other BufMut methods
to write data to the buffer.
If the pool can provide a buffer (capacity within limits and pool not exhausted), returns a pooled buffer that will be returned to the pool when dropped. Otherwise, falls back to an untracked aligned heap allocation that is deallocated when dropped.
Use Self::try_alloc if you need to distinguish between pooled and
untracked allocations.
§Initialization
The returned buffer contains uninitialized memory. Do not read from it until data has been written.
Sourcepub fn try_alloc(&self, capacity: usize) -> Result<IoBufMut, PoolError>
pub fn try_alloc(&self, capacity: usize) -> Result<IoBufMut, PoolError>
Attempts to allocate a pooled buffer, returning an error on failure.
Unlike Self::alloc, this method does not fall back to untracked
allocation. Use this when you need to know whether the buffer came
from the pool.
§Errors
PoolError::Oversized:capacityexceedsmax_sizePoolError::Exhausted: Pool exhausted for required size class
Sourcepub fn config(&self) -> &BufferPoolConfig
pub fn config(&self) -> &BufferPoolConfig
Returns the pool configuration.
Trait Implementations§
Source§impl Clone for BufferPool
impl Clone for BufferPool
Source§fn clone(&self) -> BufferPool
fn clone(&self) -> BufferPool
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BufferPool
impl !RefUnwindSafe for BufferPool
impl Send for BufferPool
impl Sync for BufferPool
impl Unpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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