napi_get_arraybuffer_info


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

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

  • [in] arraybuffernapi_value 代表正在查询的 ArrayBufferSharedArrayBuffer

    ¥[in] arraybuffer: napi_value representing the ArrayBuffer or SharedArrayBuffer being queried.

  • [out] dataArrayBufferSharedArrayBuffer 的底层数据缓冲区是 0,也可能是 NULL 或任何其他指针值。

    ¥[out] data: The underlying data buffer of the ArrayBuffer or SharedArrayBuffer is 0, this may be NULL or any other pointer value.

  • [out] byte_length:底层数据缓冲区的字节长度。

    ¥[out] byte_length: Length in bytes of the underlying data buffer.

如果 API 成功,则返回 napi_ok

¥Returns napi_ok if the API succeeded.

此 API 用于检索 ArrayBufferSharedArrayBuffer 的底层数据缓冲区及其长度。

¥This API is used to retrieve the underlying data buffer of an ArrayBuffer or SharedArrayBuffer and its length.

WARNING:使用此 API 时要小心。底层数据缓冲区的生命周期由 ArrayBufferSharedArrayBuffer 管理,即使在返回之后也是如此。使用此 API 的一种可能的安全方法是与 napi_create_reference 结合使用,这可用于保证对 ArrayBufferSharedArrayBuffer 的生命周期的控制。只要没有对可能触发 GC 的其他 API 的调用,在同一回调中使用返回的数据缓冲区也是安全的。

¥WARNING: Use caution while using this API. The lifetime of the underlying data buffer is managed by the ArrayBuffer or SharedArrayBuffer even after it's returned. A possible safe way to use this API is in conjunction with napi_create_reference, which can be used to guarantee control over the lifetime of the ArrayBuffer or SharedArrayBuffer. It's also safe to use the returned data buffer within the same callback as long as there are no calls to other APIs that might trigger a GC.