Skip to content
napi-bindings

Search

Search pages, projects and the Node-API reference

Browse Node-APIshow

node_api_create_sharedarraybuffer

functionexperimentaljs_native_api.h

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.

Stability: 1 - Experimental

napi_status node_api_create_sharedarraybuffer(napi_env env,
                                             size_t byte_length,
                                             void** data,
                                             napi_value* result)
  • [in] env: The environment that the API is invoked under.
  • [in] byte_length: The length in bytes of the shared array buffer to create.
  • [out] data: Pointer to the underlying byte buffer of the SharedArrayBuffer. data can optionally be ignored by passing NULL.
  • [out] result: A napi_value representing a JavaScript SharedArrayBuffer.

Returns napi_ok if the API succeeded.

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.

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 objects are described in Section SharedArrayBuffer objects of the ECMAScript Language Specification.

View in the official Node.js documentation