WasmSharedMemoryBlock Class

The bytes of a shared memory, allocated once for the capacity of the memory, whose address never changes: the memory grows within the capacity. The default blocks are pinned .NET arrays; set WasmStoreOptions.SharedMemoryAllocator to provide the bytes (e.g. the data block of a SharedArrayBuffer of a script engine). The members can be called from any thread.

public abstract class WasmSharedMemoryBlock

Constructors

NameDescription
WasmSharedMemoryBlock(nint, ulong)Initializes a block.

WasmSharedMemoryBlock(nint, ulong)

WasmObjects.cs

Initializes a block.

protected WasmSharedMemoryBlock(nint address, ulong capacity)

Parameters

address nint
The address of the first byte, which must not change while the block is alive.
capacity ulong
The number of bytes allocated at address.

Properties

NameDescription
AddressGets the address of the first byte, which never changes.
ByteLengthGets the current size of the memory in bytes.
CapacityGets the number of bytes the memory can grow to.

Gets the address of the first byte, which never changes.

public nint Address { get; }

Property value

nint

ByteLength

Gets the current size of the memory in bytes.

public abstract ulong ByteLength { get; }

Property value

ulong

Gets the number of bytes the memory can grow to.

public ulong Capacity { get; }

Property value

ulong

Methods

NameDescription
GetSpan()Returns the bytes of the memory: the span is valid while the block is alive.
TryGrow(ulong)Grows the bytes to newByteLength (the new bytes must be zeroed), and returns false when it is less than the current length or greater than the capacity.

Returns the bytes of the memory: the span is valid while the block is alive.

public Span<byte> GetSpan()

Returns

Span<byte>

TryGrow(ulong)

Grows the bytes to newByteLength (the new bytes must be zeroed), and returns false when it is less than the current length or greater than the capacity.

public abstract bool TryGrow(ulong newByteLength)

Parameters

newByteLength ulong

Returns

bool