pub struct KvCachePool { /* private fields */ }Expand description
A pool of KV-cache pages.
Pages are fixed-size slabs of f32 data backed by a single Vec per page.
The pool uses a simple free-list: allocated pages are handed out by
returning their index, and freed pages are pushed back onto the list.
The pool never shrinks — once a page is allocated it lives until the pool is dropped.
Implementations§
Source§impl KvCachePool
impl KvCachePool
Sourcepub fn new(page_size: usize, initial_pages: usize) -> Self
pub fn new(page_size: usize, initial_pages: usize) -> Self
Create a new pool with initial_pages pre-allocated pages of
page_size f32 elements each.
All pages start on the free list, ready for immediate allocation.
Sourcepub fn alloc(&mut self) -> Option<usize>
pub fn alloc(&mut self) -> Option<usize>
Allocate a page from the free list.
Returns Some(page_idx) on success, or None if the pool is
exhausted. The caller must pass the returned index to free when
the page is no longer needed.
Sourcepub fn free(&mut self, page_idx: usize)
pub fn free(&mut self, page_idx: usize)
Return page page_idx to the free list.
The page data is not zeroed; callers should zero or overwrite the slice before treating it as a fresh allocation.
§Panics
Panics in debug builds if page_idx >= total_pages().
Sourcepub fn total_pages(&self) -> usize
pub fn total_pages(&self) -> usize
Total number of pages ever allocated (including those on the free list).
Sourcepub fn free_pages(&self) -> usize
pub fn free_pages(&self) -> usize
Number of pages currently on the free list (available for allocation).
Sourcepub fn used_pages(&self) -> usize
pub fn used_pages(&self) -> usize
Number of pages currently in use (allocated but not yet freed).
Auto Trait Implementations§
impl Freeze for KvCachePool
impl RefUnwindSafe for KvCachePool
impl Send for KvCachePool
impl Sync for KvCachePool
impl Unpin for KvCachePool
impl UnsafeUnpin for KvCachePool
impl UnwindSafe for KvCachePool
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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