pub struct BufferPool { /* private fields */ }Expand description
Standard thread-safe buffer pool backed by a Mutex.
Simple and reliable; suitable for most applications.
For maximum throughput in high-contention scenarios, prefer
crate::pool::FastBufferPool.
§Thread Safety
Can be shared across threads via Arc.
§Example
use secbuf::prelude::*;
let pool = BufferPool::new(PoolConfig {
buffer_size: 4096,
max_pool_size: 100,
min_pool_size: 10,
});
let mut buf = pool.acquire();
buf.put_u32(42)?;
// Buffer is burned (zeroed) then returned to the pool on drop.Implementations§
Source§impl BufferPool
impl BufferPool
Sourcepub fn new(config: PoolConfig) -> Self
pub fn new(config: PoolConfig) -> Self
Creates a new buffer pool and pre-warms it with config.min_pool_size buffers.
Sourcepub fn acquire(&self) -> PooledBuffer
pub fn acquire(&self) -> PooledBuffer
Acquires a buffer from the pool, allocating a fresh one if the pool is empty.
The returned PooledBuffer is automatically burned and returned (or
dropped) when it goes out of scope.
Sourcepub fn shrink(&self)
pub fn shrink(&self)
Truncates idle buffers to min_pool_size, freeing excess memory.
Excess buffers are securely zeroed before being dropped.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BufferPool
impl RefUnwindSafe for BufferPool
impl Send for BufferPool
impl Sync for BufferPool
impl Unpin for BufferPool
impl UnsafeUnpin 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