WasmMemory Class
A memory (a memory address). The bytes of a memory that is not shared are a .NET array (WasmMemory.Data), replaced when the memory grows. The bytes of a shared memory are a WasmSharedMemoryBlock, which never moves: a shared memory can be used by the stores of every thread, and its methods can be called from any thread.
public abstract class WasmMemory : WasmExtern- Inheritance
WasmExternWasmMemory
Properties
| Name | Description |
|---|---|
| Data | Gets the bytes of a memory that is not shared (the length is the size of the memory in bytes). The array is replaced when the memory grows (see WasmMemory.DataChanged): do not keep it. |
| Kind | Gets the kind of the value. |
| SharedBlock | Gets the bytes of a shared memory, or null for a memory that is not shared. |
| Size | Gets the size of the memory in pages. |
| Type | Gets the type of the memory. |
Data
Gets the bytes of a memory that is not shared (the length is the size of the memory in bytes). The array is replaced when the memory grows (see WasmMemory.DataChanged): do not keep it.
public abstract byte[] Data { get; }Kind
WasmObjects.csSize
Type
Methods
| Name | Description |
|---|---|
| AtomicNotify(ulong, uint) | Notifies the waiters of an address of a shared memory (memory.atomic.notify), from any thread, and returns the number of waiters notified. |
| AtomicWait(ulong, long, int, TimeSpan?, WasmWaitSignal?) | Blocks the calling thread until a waiter of an address of a shared memory is notified or the timeout elapses (memory.atomic.wait32 and memory.atomic.wait64), when the address contains expected. It can be called from any thread. |
| GetSpan() | Returns the bytes of the memory. The span is invalid after the memory grows, unless the memory is shared. |
| Grow(ulong) | Grows the memory (mem_grow) and returns its previous size in pages. |
| GrowTo(ulong) | Grows the memory to newSize pages, and returns its previous size in pages: the memory does not change when its size is newSize or more. The threads that share a memory can grow it concurrently: a shared memory grows to the new size, never beyond it. |
AtomicNotify(ulong, uint)
WasmObjects.csNotifies the waiters of an address of a shared memory (memory.atomic.notify), from any thread, and returns the number of waiters notified.
Parameters
Returns
Exceptions
WasmTrapException- The address is out of bounds or not aligned.
NotSupportedException- The memory is not shared.
AtomicWait(ulong, long, int, TimeSpan?, WasmWaitSignal?)
WasmObjects.csBlocks the calling thread until a waiter of an address of a shared memory is notified or the timeout elapses (memory.atomic.wait32 and memory.atomic.wait64), when the address contains expected. It can be called from any thread.
public virtual WasmWaitResult AtomicWait(ulong address, long expected, int size, TimeSpan? timeout, WasmWaitSignal? signal = null)Parameters
addressulong- The address: a multiple of
size. expectedlong- The expected value (the low 32 bits for a 32-bit wait).
sizeint- The size of the value in bytes: 4 or 8.
timeoutTimeSpan?- The maximum duration of the wait, or null to wait until notified.
signalWasmWaitSignal?- Set right before the thread joins the waiters of the address, or null.
Returns
Exceptions
WasmTrapException- The address is out of bounds or not aligned.
NotSupportedException- The memory is not shared.
GetSpan()
WasmObjects.csReturns the bytes of the memory. The span is invalid after the memory grows, unless the memory is shared.
Returns
Grow(ulong)
Grows the memory (mem_grow) and returns its previous size in pages.
Parameters
deltaulong- The number of pages to add.
Returns
Exceptions
WasmAllocationException- The memory cannot grow.
GrowTo(ulong)
WasmObjects.csGrows the memory to newSize pages, and returns its previous size in pages: the memory does not change when its size is newSize or more. The threads that share a memory can grow it concurrently: a shared memory grows to the new size, never beyond it.
Parameters
newSizeulong- The size in pages.
Returns
Exceptions
WasmAllocationException- The memory cannot grow.
Events
| Name | Description |
|---|---|
| DataChanged | Occurs after the bytes of a memory that is not shared are replaced: the memory grew, by WasmMemory.Grow or by a memory.grow instruction. It is raised on the thread of the store. |
DataChanged
Occurs after the bytes of a memory that is not shared are replaced: the memory grew, by WasmMemory.Grow or by a memory.grow instruction. It is raised on the thread of the store.
public event EventHandler? DataChanged