napi_create_array_with_length
napi_status napi_create_array_with_length(napi_env env,
size_t length,
napi_value* result) [in] env:调用该 API 时所处的环境。[in] length:Array的初始长度。[out] result:一个表示 JavaScriptArray的napi_value。
如果 API 成功,则返回 napi_ok。
【Returns napi_ok if the API succeeded.】
此 API 返回一个与 JavaScript Array 类型对应的 Node-API 值。
Array 的 length 属性将被设置为传入的 length 参数。
然而,当数组创建时,底层缓冲区不保证会被虚拟机预先分配。该行为由底层虚拟机实现决定。如果缓冲区必须是一个可以通过 C 直接读取和/或写入的连续内存块,请考虑使用 napi_create_external_arraybuffer。
【This API returns a Node-API value corresponding to a JavaScript Array type.
The Array's length property is set to the passed-in length parameter.
However, the underlying buffer is not guaranteed to be pre-allocated by the VM
when the array is created. That behavior is left to the underlying VM
implementation. If the buffer must be a contiguous block of memory that can be
directly read and/or written via C, consider using
napi_create_external_arraybuffer.】
JavaScript 数组在 ECMAScript 语言规范的 数组对象 中有所描述。
【JavaScript arrays are described in Section Array objects of the ECMAScript Language Specification.】