pub struct BlockAllocator { /* private fields */ }Expand description
LIFO free-list block allocator. O(1) allocate / free, no fragmentation
(all blocks are uniform size).
capacity is the total physical block count baked into the pool at
load time. The allocator is independent per-model (block index space
is not portable across models).
Implementations§
Source§impl BlockAllocator
impl BlockAllocator
Sourcepub fn new(num_blocks: u32) -> Self
pub fn new(num_blocks: u32) -> Self
Create a fresh allocator. All num_blocks blocks start free.
Free-list is built so allocate() returns block 0 first, then 1,
etc. — predictable for tests and ensures the lower physical
blocks see the most reuse (better cache locality on M1’s SLC).
Sourcepub fn allocate(&mut self) -> Result<u32>
pub fn allocate(&mut self) -> Result<u32>
Allocate a single physical block. Returns Err when the pool is
exhausted — caller is expected to refuse the request and queue
it (or evict another seq, when that’s wired up).
Sourcepub fn allocate_n(&mut self, n: usize) -> Result<Vec<u32>>
pub fn allocate_n(&mut self, n: usize) -> Result<Vec<u32>>
Bulk allocate. Atomic: either all n succeed or none are taken.
Sourcepub fn free(&mut self, blocks: &[u32])
pub fn free(&mut self, blocks: &[u32])
Return blocks to the free list. Caller is responsible for
ensuring no live sequence still references them; freeing a block
while it’s still in a PagedSeqState::blocks will silently
corrupt the next allocation that gets it.
pub fn free_count(&self) -> usize
pub fn capacity(&self) -> u32
pub fn peak_in_use(&self) -> usize
Auto Trait Implementations§
impl !Freeze for BlockAllocator
impl RefUnwindSafe for BlockAllocator
impl Send for BlockAllocator
impl Sync for BlockAllocator
impl Unpin for BlockAllocator
impl UnsafeUnpin for BlockAllocator
impl UnwindSafe for BlockAllocator
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