pub struct BufferPool { /* private fields */ }Expand description
Page-aligned arena carved into total_chunks fixed-size chunks, handed
out and reclaimed via a TreiberStack free-list.
Implementations§
Source§impl BufferPool
impl BufferPool
Sourcepub fn new(total_chunks: usize, chunk_size: usize) -> Self
pub fn new(total_chunks: usize, chunk_size: usize) -> Self
Allocate a page-aligned arena of total_chunks chunks of
chunk_size bytes each, with all chunks initially free.
§Panics
Panics if total_chunks * chunk_size (each floored to at least 1)
overflows or produces a layout with invalid size/alignment for the
global allocator (Layout::from_size_align failure), or if the
allocator itself fails to satisfy the allocation
(handle_alloc_error).
Sourcepub const fn get_ptr(&self, idx: u32) -> *mut u8
pub const fn get_ptr(&self, idx: u32) -> *mut u8
Raw pointer to the start of chunk idx within the arena. idx
must be < total_chunks as passed to Self::new — out-of-range
indices produce a pointer outside the arena allocation, which is
unsound to dereference (this function itself performs no
dereference, only pointer arithmetic).
Sourcepub const fn chunk_size(&self) -> usize
pub const fn chunk_size(&self) -> usize
The fixed chunk size (in bytes) this pool was constructed with.