pub struct StorageBudget(/* private fields */);Expand description
Shared allowance for buffers created through this allocator.
Admission is thread-safe and occurs before vector allocation. Failed allocation releases its reservation. A view of one byte retains the charge for its whole backing allocation, including row padding and unused capacity.
Implementations§
Source§impl StorageBudget
impl StorageBudget
Sourcepub fn new(max_bytes: usize, max_objects: usize) -> StorageBudget
pub fn new(max_bytes: usize, max_objects: usize) -> StorageBudget
Set independent byte and allocation-count limits. Zero is a real limit.
Sourcepub fn reserved_bytes(&self) -> usize
pub fn reserved_bytes(&self) -> usize
Bytes currently reserved, including admitted allocations still being built.
Sourcepub fn reserved_objects(&self) -> usize
pub fn reserved_objects(&self) -> usize
Allocation slots currently reserved. Reading this and reserved_bytes
separately is diagnostic, not an atomic two-counter snapshot.
Sourcepub fn max_objects(&self) -> usize
pub fn max_objects(&self) -> usize
The allocation-count allowance.
Sourcepub fn bytes(&self, len: usize) -> Result<OwnedStorage<u8>, StorageError>
pub fn bytes(&self, len: usize) -> Result<OwnedStorage<u8>, StorageError>
Allocate zeroed bytes after admission. Mutation cannot resize the buffer.
Sourcepub fn words(&self, len: usize) -> Result<OwnedStorage<u16>, StorageError>
pub fn words(&self, len: usize) -> Result<OwnedStorage<u16>, StorageError>
Allocate zeroed 16-bit words, charging two bytes per word.
Sourcepub fn floats(&self, len: usize) -> Result<OwnedStorage<f32>, StorageError>
pub fn floats(&self, len: usize) -> Result<OwnedStorage<f32>, StorageError>
Allocate zeroed 32-bit floating-point samples, charging four bytes each.
Sourcepub fn filled<T>(
&self,
len: usize,
value: T,
) -> Result<OwnedStorage<T>, StorageError>where
T: Copy,
pub fn filled<T>(
&self,
len: usize,
value: T,
) -> Result<OwnedStorage<T>, StorageError>where
T: Copy,
Allocate a fixed array of copyable values after byte/object admission. This also admits bounded codec tables and range indexes. Any storage referenced by a value is separate; only this array’s capacity is charged.
Sourcepub fn prepare_filled<T>(
&self,
len: usize,
value: T,
) -> Result<PreparedStorage<T>, StorageError>where
T: Copy,
pub fn prepare_filled<T>(
&self,
len: usize,
value: T,
) -> Result<PreparedStorage<T>, StorageError>where
T: Copy,
Reserve array capacity without allocating or initializing its payload.
Use this before a policy callback so the route can hold its allowance without materializing a large destination. Drop an unselected reservation to release it; allocation still may fail after policy selects the route. The stored fill value and allocator bookkeeping are outside the charge.
Trait Implementations§
Source§impl Clone for StorageBudget
impl Clone for StorageBudget
Source§fn clone(&self) -> StorageBudget
fn clone(&self) -> StorageBudget
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more