node_api_create_sharedarraybuffer


稳定性: 1 - 实验性的

¥Stability: 1 - Experimental

napi_status node_api_create_sharedarraybuffer(napi_env env,
                                             size_t byte_length,
                                             void** data,
                                             napi_value* result) 
  • [in] env:调用 API 的环境。

    ¥[in] env: The environment that the API is invoked under.

  • [in] byte_length:要创建的共享数组缓冲区的长度(以字节为单位)。

    ¥[in] byte_length: The length in bytes of the shared array buffer to create.

  • [out] data:指向 SharedArrayBuffer 的底层字节缓冲区的指针。data 可以选择性地通过传递 NULL 来忽略。

    ¥[out] data: Pointer to the underlying byte buffer of the SharedArrayBuffer. data can optionally be ignored by passing NULL.

  • [out] result:代表 JavaScript SharedArrayBuffernapi_value

    ¥[out] result: A napi_value representing a JavaScript SharedArrayBuffer.

如果 API 成功,则返回 napi_ok

¥Returns napi_ok if the API succeeded.

此 API 返回对应于 JavaScript SharedArrayBuffer 的 Node-API 值。SharedArrayBuffer 用于表示可在多个 Worker 之间共享的固定长度二进制数据缓冲区。

¥This API returns a Node-API value corresponding to a JavaScript SharedArrayBuffer. SharedArrayBuffers are used to represent fixed-length binary data buffers that can be shared across multiple workers.

分配的 SharedArrayBuffer 将有一个底层字节缓冲区,其大小由传入的 byte_length 参数决定。如果调用者想要直接操作缓冲区,则可以选择将底层缓冲区返回给调用者。此缓冲区只能直接从原生代码写入。要从 JavaScript 写入此缓冲区,需要创建类型化数组或 DataView 对象。

¥The SharedArrayBuffer allocated will have an underlying byte buffer whose size is determined by the byte_length parameter that's passed in. The underlying buffer is optionally returned back to the caller in case the caller wants to directly manipulate the buffer. This buffer can only be written to directly from native code. To write to this buffer from JavaScript, a typed array or DataView object would need to be created.

JavaScript SharedArrayBuffer 对象在 ECMAScript 语言规范的 SharedArrayBuffer 对象部分 中进行了描述。

¥JavaScript SharedArrayBuffer objects are described in Section SharedArrayBuffer objects of the ECMAScript Language Specification.