Skip to main content

BufferPool

Struct BufferPool 

Source
pub struct BufferPool { /* private fields */ }
Expand description

Fixed-size recyclable buffer pool.

§Examples

use santh_bufpool::{BufferPool, PoolConfig};

let pool = BufferPool::new(PoolConfig {
    four_kib_count: 1,
    ..PoolConfig::default()
});
let buffer = pool.checkout(32).unwrap();
assert_eq!(buffer.len(), 32);

Implementations§

Source§

impl BufferPool

Source

pub fn new(config: PoolConfig) -> Self

Create a new buffer pool from the supplied configuration.

NUMA placement is best-effort. If kernelkit cannot place pages on the requested node, allocation falls back to a standard heap buffer.

Source

pub fn stats(&self) -> &PoolStats

Access pool statistics.

Source

pub fn checkout(&self, min_bytes: usize) -> Result<PoolBuffer>

Check out a buffer with at least min_bytes of capacity.

The returned slice length matches min_bytes. Its backing allocation is guaranteed to be at least min_bytes but may be up to 1 MiB.

§Errors

Returns an error if min_bytes exceeds isize::MAX.

Source

pub fn checkout_zeroed(&self, min_bytes: usize) -> Result<PoolBuffer>

Check out a buffer and explicitly zero its visible contents.

Recycled buffers are zeroed before being returned to the pool, so this is mostly useful if you need to ensure the buffer is zeroed immediately prior to use (e.g. for cryptographic materials).

§Errors

Returns an error if min_bytes exceeds isize::MAX.

Source

pub fn checkout_aligned( &self, min_bytes: usize, alignment: usize, ) -> Result<PoolBuffer>

Check out a buffer with best-effort alignment.

The pool will attempt to provide a buffer aligned to alignment bytes, but this is not guaranteed for alignments larger than the platform’s default heap alignment (typically 8 or 16 bytes). For SIMD (32-byte), this typically works. For page alignment (4096), use OS-specific allocators.

§Errors

Returns an error if min_bytes exceeds platform limits or alignment is not a power of two.

Trait Implementations§

Source§

impl Debug for BufferPool

Source§

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

Formats the value using the given formatter. 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> 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, 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.