pub struct BufferPool { /* private fields */ }Expand description
Lock-free buffer pool for reusing large I/O buffers Uses crossbeam’s SegQueue for lock-free operations
Implementations§
Source§impl BufferPool
impl BufferPool
Sourcepub fn new(buffer_size: BufferSize, max_pool_size: usize) -> Self
pub fn new(buffer_size: BufferSize, max_pool_size: usize) -> Self
Create a new buffer pool with pre-allocated buffers
§Arguments
buffer_size- Size of each buffer in bytes (must be non-zero)max_pool_size- Maximum number of buffers to pool
All buffers are pre-allocated at creation time for optimal performance.
Sourcepub async fn get_buffer(&self) -> PooledBuffer
pub async fn get_buffer(&self) -> PooledBuffer
Get a buffer from the pool or create a new one (lock-free)
Returns a PooledBuffer that automatically returns to the pool when dropped. The buffer may contain old data, but this is safe because:
- Callers use AsyncRead which writes into the buffer
- They get back
nbytes written and access only&buf[..n] - Stale data beyond
nis never accessed
Sourcepub async fn return_buffer(&self, buffer: Vec<u8>)
pub async fn return_buffer(&self, buffer: Vec<u8>)
Return a buffer to the pool (lock-free)
Note: Usually not needed as PooledBuffer returns itself automatically on drop
Trait Implementations§
Source§impl Clone for BufferPool
impl Clone for BufferPool
Source§fn clone(&self) -> BufferPool
fn clone(&self) -> BufferPool
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
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
Mutably borrows from an owned value. Read more