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] arraybuffer
:napi_value
代表被查询的ArrayBuffer
。¥
[in] arraybuffer
:napi_value
representing theArrayBuffer
being queried. -
[out] data
:ArrayBuffer
的底层数据缓冲区。如果 byte_length 是0
,则这可能是NULL
或任何其他指针值。¥
[out] data
: The underlying data buffer of theArrayBuffer
. If byte_length is0
, this may beNULL
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 用于检索 ArrayBuffer
的底层数据缓冲区及其长度。
¥This API is used to retrieve the underlying data buffer of an ArrayBuffer
and
its length.
WARNING:使用此 API 时要小心。底层数据缓冲区的生命周期由 ArrayBuffer
管理,即使在返回后也是如此。使用此 API 的一种可能的安全方法是与 napi_create_reference
结合使用,它可用于保证对 ArrayBuffer
生命周期的控制。只要没有对可能触发 GC 的其他 API 的调用,在同一回调中使用返回的数据缓冲区也是安全的。
¥WARNING: Use caution while using this API. The lifetime of the underlying data
buffer is managed by the ArrayBuffer
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
. 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.