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

source

pub fn new(store: Store, memory_type: MemoryType) -> Self

Creates a new Memory.

source

pub fn type(&self) -> MemoryType

Returns the memory type.

source

pub fn size(&self) -> Integer

Returns the size (in pages) of the memory.

source

pub fn data_size(&self) -> Integer

Returns the size (in bytes) of the memory.

source

pub fn grow(&self, number_of_pages: Integer) -> Integer

Grows memory by the specified amount of WebAssembly pages.

Example
memory = instance.exports.memory
old_memory_size = memory.data_size

memory.grow 1

memory_size = memory.data_size

assert { memory_size == 1179648 }
assert { memory_size - old_memory_size == 65536 }
source

pub fn uint8_view(&self) -> Uint8View

Creates a read-and-write view over the memory data where elements are of kind uint8.

source

pub fn int8_view(&self) -> Int8View

Creates a read-and-write view over the memory data where elements are of kind int8.

source

pub fn uint16_view(&self) -> Uint16View

Creates a read-and-write view over the memory data where elements are of kind uint16.

source

pub fn int16_view(&self) -> Int16View

Creates a read-and-write view over the memory data where elements are of kind int16.

source

pub fn uint32_view(&self) -> Uint32View

Creates a read-and-write view over the memory data where elements are of kind uint32.

source

pub fn int32_view(&self) -> Int32View

Creates a read-and-write view over the memory data where elements are of kind int32.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.