JsSharedDataBlock Class
A Shared Data Block (https://tc39.es/ecma262/#sec-data-blocks): the memory of a SharedArrayBuffer. It can be shared by several engines (agents) running on different threads, e.g. by the structured clone of a SharedArrayBuffer sent to a worker. The memory is a managed array allocated once for the maximum byte length on the pinned object heap: a growable block never moves, its byte length grows atomically. The bytes are 16-byte aligned (the atomic operations of 64-bit values are aligned). The spans, references and memories of the block reference the array, so they keep the memory alive by themselves, even once no SharedArrayBuffer references the block.
public sealed class JsSharedDataBlockProperties
| Name | Description |
|---|---|
| ByteLength | Gets the byte length ([[ArrayBufferByteLengthData]], read with the seq-cst order). |
| IsGrowable | Gets whether the block is growable. |
| MaxByteLength | Gets the maximum byte length of a growable block, or null for a fixed-length block. |
ByteLength
JsSharedDataBlock.csIsGrowable
JsSharedDataBlock.csMaxByteLength
JsSharedDataBlock.csMethods
| Name | Description |
|---|---|
| GetMemory() | Gets the bytes of the block (its current byte length) as a Memory<T>, which keeps the memory alive. |
| GetReference(int) | Gets a reference to a byte of the block (for the atomic operations); the index is less than the byte length. |
| GetSpan() | Gets the bytes of the block (its current byte length). |
| TryCreate(int, int?) | CreateSharedByteDataBlock(size): a zeroed block, or null when the memory cannot be allocated. |
| TryGrow(int) | Grows the block (SharedArrayBuffer.prototype.grow): false when the new length is less than the current length or greater than the maximum byte length. The new bytes are zeroed before the new length is published. |
GetMemory()
JsSharedDataBlock.csGets the bytes of the block (its current byte length) as a Memory<T>, which keeps the memory alive.
Returns
GetReference(int)
JsSharedDataBlock.csGetSpan()
JsSharedDataBlock.csTryCreate(int, int?)
JsSharedDataBlock.csCreateSharedByteDataBlock(size): a zeroed block, or null when the memory cannot be allocated.
public static JsSharedDataBlock? TryCreate(int byteLength, int? maxByteLength)