Struct wasmer_ruby::Wasmer::Memory
source · pub struct Memory;
Expand description
A WebAssembly memory instance.
A memory instance is the runtime representation of a linear memory. It consists of a vector of bytes and an optional maximum size.
The length of the vector always is a multiple of the WebAssembly page size, which is defined to be the constant 65536 – abbreviated 64Ki. Like in a memory type, the maximum size in a memory instance is given in units of this page size.
A memory created by the host or in WebAssembly code will be accessible and mutable from both host and WebAssembly.
Specification: https://webassembly.github.io/spec/core/exec/runtime.html#memory-instances
Example
Creates a Memory
from scratch:
store = Wasmer::Store.new
memory_type = Wasmer::MemoryType.new 3, 10, true
memory = Wasmer::Memory.new store, memory_type
assert { memory.size == 3 }
Gets a memory from the exports of an instance:
module_ = Wasmer::Module.new Wasmer::Store.new, wasm_bytes
instance = Wasmer::Instance.new module, nil
memory = instance.exports.memory
Implementations§
source§impl Memory
impl Memory
sourcepub fn new(store: Store, memory_type: MemoryType) -> Self
pub fn new(store: Store, memory_type: MemoryType) -> Self
Creates a new Memory
.
sourcepub fn type(&self) -> MemoryType
pub fn type(&self) -> MemoryType
Returns the memory type.
sourcepub fn uint8_view(&self) -> Uint8View
pub fn uint8_view(&self) -> Uint8View
Creates a read-and-write view over the memory data where
elements are of kind uint8
.
sourcepub fn int8_view(&self) -> Int8View
pub fn int8_view(&self) -> Int8View
Creates a read-and-write view over the memory data where
elements are of kind int8
.
sourcepub fn uint16_view(&self) -> Uint16View
pub fn uint16_view(&self) -> Uint16View
Creates a read-and-write view over the memory data where
elements are of kind uint16
.
sourcepub fn int16_view(&self) -> Int16View
pub fn int16_view(&self) -> Int16View
Creates a read-and-write view over the memory data where
elements are of kind int16
.
sourcepub fn uint32_view(&self) -> Uint32View
pub fn uint32_view(&self) -> Uint32View
Creates a read-and-write view over the memory data where
elements are of kind uint32
.
sourcepub fn int32_view(&self) -> Int32View
pub fn int32_view(&self) -> Int32View
Creates a read-and-write view over the memory data where
elements are of kind int32
.