pub trait MemoryLimiter: Sized {
    // Required methods
    fn memory_used(&self) -> usize;
    fn grow_memory(&mut self, delta: usize) -> bool;
    fn with_stack_frame<T, G, F, R>(t: &mut T, g: G, f: F) -> R
       where G: Fn(&mut T) -> &mut Self,
             F: FnOnce(&mut T) -> R;

    // Provided methods
    fn grow_instance_memory(&mut self, from: usize, to: usize) -> bool { ... }
    fn grow_instance_table(&mut self, from: u32, to: u32) -> bool { ... }
}
Expand description

Execution level memory tracking and adjustment.

Required Methods§

source

fn memory_used(&self) -> usize

Get a snapshot of the total memory required by the callstack (in bytes). This currently includes:

  • Memory used by tables (8 bytes per element).
  • Memory used by wasmtime instances.

In the future, this will likely be extended to include IPLD blocks, actor code, etc.

source

fn grow_memory(&mut self, delta: usize) -> bool

Returns true if growing by delta bytes is allowed. Implement this memory to track and limit memory usage.

source

fn with_stack_frame<T, G, F, R>(t: &mut T, g: G, f: F) -> R
where G: Fn(&mut T) -> &mut Self, F: FnOnce(&mut T) -> R,

Push a new frame onto the call stack, and keep tallying up the current execution memory, then restore it to the current value when the frame is finished.

Provided Methods§

source

fn grow_instance_memory(&mut self, from: usize, to: usize) -> bool

Grows an instance’s memory from from to to. There’s no need to manually implement this unless you need to track instance metrics.

source

fn grow_instance_table(&mut self, from: u32, to: u32) -> bool

Grows an instance’s table from from to to elements. There’s no need to manually implement this unless you need to track table metrics.

Object Safety§

This trait is not object safe.

Implementors§