pub struct Memory { /* private fields */ }Expand description
A shared storage domain retained by owned results.
Cloning this handle shares existing state and allocates no new block.
Implementations§
Source§impl Memory
impl Memory
Sourcepub fn new(account: Arc<MemoryAccount>) -> Self
pub fn new(account: Arc<MemoryAccount>) -> Self
Uses caller-supplied shared state; this constructor allocates nothing.
Sourcepub fn used(&self) -> usize
pub fn used(&self) -> usize
Currently reserved bytes, including pending allocations and growth peaks.
Sourcepub fn same_account(&self, other: &Self) -> bool
pub fn same_account(&self, other: &Self) -> bool
Whether two handles share exactly the same account, without allocation.
Sourcepub fn work_used(&self) -> usize
pub fn work_used(&self) -> usize
Cumulative work already admitted, including operations that later failed.
Sourcepub fn work_remaining(&self) -> usize
pub fn work_remaining(&self) -> usize
Currently available aggregate work units, without reserving them.
Concurrent consumption can reduce this observation; every operation
must still use Self::charge_work before execution.
Sourcepub fn charge_work(&self, amount: u64) -> Result<(), MemoryError>
pub fn charge_work(&self, amount: u64) -> Result<(), MemoryError>
Charges work before performing it; storage release never refunds work.
An amount unrepresentable on this target is refused before any work, preserving the existing u64 scanning API on 32-bit targets.
Sourcepub fn reserve(&self, bytes: usize) -> Result<MemoryReservation, MemoryError>
pub fn reserve(&self, bytes: usize) -> Result<MemoryReservation, MemoryError>
Reserves storage for an adapter-owned allocation before allocating it.
Keep the returned guard until after deallocation, including rollback on failure. Reserve the complete actual capacity; a growth must retain the old guard while admitting the replacement. This bridge does not allocate.
Sourcepub fn vector<T>(&self) -> OwnedVec<T>
pub fn vector<T>(&self) -> OwnedVec<T>
An empty owned collection sharing this domain, without allocating storage.
Sourcepub fn map<K: HashWork, V>(&self) -> OwnedMap<K, V>
pub fn map<K: HashWork, V>(&self) -> OwnedMap<K, V>
An empty accounted hash map, without allocating storage.
Sourcepub fn string(&self) -> OwnedString
pub fn string(&self) -> OwnedString
Empty accounted UTF-8 text, without allocating storage.