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
impl BufferPool
Sourcepub fn new(config: PoolConfig) -> Self
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.
Sourcepub fn checkout(&self, min_bytes: usize) -> Result<PoolBuffer>
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.
Sourcepub fn checkout_zeroed(&self, min_bytes: usize) -> Result<PoolBuffer>
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.
Sourcepub fn checkout_aligned(
&self,
min_bytes: usize,
alignment: usize,
) -> Result<PoolBuffer>
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.