[−][src]Struct wasmer::Memory
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.
Spec: https://webassembly.github.io/spec/core/exec/runtime.html#memory-instances
Implementations
impl Memory
[src]
pub fn new(store: &Store, ty: MemoryType) -> Result<Memory, MemoryError>
[src]
Creates a new host Memory
from the provided MemoryType
.
This function will construct the Memory
using the store Tunables
.
pub fn ty(&self) -> &MemoryType
[src]
Returns the MemoryType
of the Memory
.
pub fn store(&self) -> &Store
[src]
Returns the Store
where the Memory
belongs.
pub unsafe fn data_unchecked(&self) -> &[u8]ⓘ
[src]
pub unsafe fn data_unchecked_mut(&self) -> &mut [u8]ⓘ
[src]
TODO: document this function, it's trivial to cause UB/break soundness with this method.
Safety
To be defined (TODO).
pub fn data_ptr(&self) -> *mut u8
[src]
Returns the pointer to the raw bytes of the Memory
.
pub fn data_size(&self) -> usize
[src]
Returns the size (in bytes) of the Memory
.
pub fn size(&self) -> Pages
[src]
Returns the size (in Pages
) of the Memory
.
pub fn grow<IntoPages>(&self, delta: IntoPages) -> Result<Pages, MemoryError> where
IntoPages: Into<Pages>,
[src]
IntoPages: Into<Pages>,
Grow memory by the specified amount of WebAssembly Pages
.
Errors
Returns an error if memory can't be grown by the specified amount of pages.
pub fn view<T: ValueType>(&self) -> MemoryView<'_, T>
[src]
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 MemoryView::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); }
pub fn same(&self, other: &Memory) -> bool
[src]
Returns whether or not these two globals refer to the same data.
Trait Implementations
impl Clone for Memory
[src]
impl Debug for Memory
[src]
impl<'a> Exportable<'a> for Memory
[src]
fn to_export(&self) -> Export
[src]
fn get_self_from_extern(_extern: &'a Extern) -> Result<&'a Self, ExportError>
[src]
impl From<Memory> for Extern
[src]
Auto Trait Implementations
impl !RefUnwindSafe for Memory
impl Send for Memory
impl Sync for Memory
impl Unpin for Memory
impl !UnwindSafe for Memory
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,