Skip to main content

BufferPool

Struct BufferPool 

Source
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

Source

pub fn new(default_size: usize, max_size: usize, name: &str) -> Self

Create a new buffer pool

§Arguments
  • default_size - Initial size for allocated buffers
  • max_size - Maximum buffer size (buffers larger than this are discarded)
  • name - Name of the pool (for debugging/logging)
Source

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

Source

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.

Source

pub fn get_with_capacity(&self, capacity: usize) -> Vec<u8>

Get a buffer with at least the specified capacity

Source

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.

Source

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.

Source

pub fn get_optimal_size(&self) -> usize

Get the current optimal size based on calibration

Source

pub fn default_size(&self) -> usize

Get the current default buffer size

Source

pub fn max_size(&self) -> usize

Get the maximum allowed buffer size

Source

pub fn name(&self) -> &str

Get the pool name

Source

pub fn available(&self) -> usize

Get the number of buffers currently in the pool

Source

pub fn stats(&self) -> PoolStats

Get statistics about the pool

Trait Implementations§

Source§

impl Debug for BufferPool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BufferPool

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CompactArcDrop for T

Source§

unsafe fn drop_and_dealloc(ptr: *mut u8)

Drop the contained data and deallocate the header+data allocation. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V