Struct wasmer_runtime_fl::Memory[][src]

pub struct Memory { /* fields omitted */ }
Expand description

A shared or unshared wasm linear memory.

A Memory represents the memory used by a wasm instance.

Implementations

Create a new Memory from a MemoryDescriptor

Usage:

fn create_memory() -> Result<()> {
    let descriptor = MemoryDescriptor::new(Pages(10), None, false).unwrap();

    let memory = Memory::new(descriptor)?;
    Ok(())
}

Return the MemoryDescriptor that this memory was created with.

Grow this memory by the specified number of pages.

The size, in wasm pages, of this memory.

Return a “view” of the currently accessible memory. By default, the view is unsynchronized, using regular memory accesses. You can force a memory view to use atomic accesses by calling the atomically method.

Notes:

This method is safe (as in, it won’t cause the host to crash or have UB), but it doesn’t obey rust’s rules involving data races, especially concurrent ones. Therefore, if this memory is shared between multiple threads, a single memory location can be mutated concurrently without synchronization.

Usage:

// Without synchronization.
let view: MemoryView<u8> = memory.view();
for byte in view[0x1000 .. 0x1010].iter().map(Cell::get) {
    println!("byte: {}", byte);
}

// With synchronization.
let atomic_view = view.atomically();
for byte in atomic_view[0x1000 .. 0x1010].iter().map(|atom| atom.load(Ordering::SeqCst)) {
    println!("byte: {}", byte);
}

Returns the module local memory.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Implementation of how to get the export corresponding to the implementing type from an [Instance] by name. Read more

Gets self as Export.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.