pub struct BufferPool { /* private fields */ }Expand description
Self-tuning buffer pool for efficient memory reuse
The pool automatically adjusts buffer sizes based on observed usage patterns via the PoolCalibrator. Buffers are reused to reduce allocation overhead.
§Example
use stoolap::common::BufferPool;
let pool = BufferPool::new(4096, 1024 * 1024, "test");
// Get a buffer from the pool
let mut buf = pool.get();
buf.extend_from_slice(b"hello world");
// Return the buffer to the pool for reuse
pool.put(buf);Implementations§
Source§impl BufferPool
impl BufferPool
Sourcepub fn new(default_size: usize, max_size: usize, name: &str) -> Self
pub fn new(default_size: usize, max_size: usize, name: &str) -> Self
Create a new buffer pool
§Arguments
default_size- Initial size for allocated buffersmax_size- Maximum buffer size (buffers larger than this are discarded)name- Name of the pool (for debugging/logging)
Sourcepub fn with_pool_size(
default_size: usize,
max_size: usize,
name: &str,
pool_size: usize,
) -> Self
pub fn with_pool_size( default_size: usize, max_size: usize, name: &str, pool_size: usize, ) -> Self
Create a new buffer pool with specified pool size
Sourcepub fn get(&self) -> Vec<u8> ⓘ
pub fn get(&self) -> Vec<u8> ⓘ
Get a buffer from the pool
Returns a buffer from the pool if available, otherwise creates a new one. The buffer is cleared before returning.
Sourcepub fn get_with_capacity(&self, capacity: usize) -> Vec<u8> ⓘ
pub fn get_with_capacity(&self, capacity: usize) -> Vec<u8> ⓘ
Get a buffer with at least the specified capacity
Sourcepub fn put(&self, buf: Vec<u8>)
pub fn put(&self, buf: Vec<u8>)
Return a buffer to the pool
The buffer is cleared and returned to the pool for reuse. Buffers larger than max_size are discarded to prevent memory bloat.
Sourcepub fn record_size(&self, size: usize)
pub fn record_size(&self, size: usize)
Record a buffer size for calibration
This is called automatically during put(), but can also be called manually to record sizes without returning a buffer.
Sourcepub fn get_optimal_size(&self) -> usize
pub fn get_optimal_size(&self) -> usize
Get the current optimal size based on calibration
Sourcepub fn default_size(&self) -> usize
pub fn default_size(&self) -> usize
Get the current default buffer size
Trait Implementations§
Source§impl Debug for BufferPool
impl Debug for BufferPool
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
Source§impl<T> CompactArcDrop for T
impl<T> CompactArcDrop for T
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