ArrayBuffer

The Napi::ArrayBuffer class corresponds to the JavaScript ArrayBuffer class.

Methods

New

Allocates a new Napi::ArrayBuffer instance with a given length.

cpp static Napi::ArrayBuffer Napi::ArrayBuffer::New(napi_env env, size_t byteLength);

Returns a new Napi::ArrayBuffer instance.

New

Wraps the provided external data into a new Napi::ArrayBuffer instance.

The Napi::ArrayBuffer instance does not assume ownership for the data and expects it to be valid for the lifetime of the instance. Since the Napi::ArrayBuffer is subject to garbage collection this overload is only suitable for data which is static and never needs to be freed.

cpp static Napi::ArrayBuffer Napi::ArrayBuffer::New(napi_env env, void* externalData, size_t byteLength);

Returns a new Napi::ArrayBuffer instance.

New

Wraps the provided external data into a new Napi::ArrayBuffer instance.

The Napi::ArrayBuffer instance does not assume ownership for the data and expects it to be valid for the lifetime of the instance. The data can only be freed once the finalizeCallback is invoked to indicate that the Napi::ArrayBuffer has been released.

cpp template <typename Finalizer> static Napi::ArrayBuffer Napi::ArrayBuffer::New(napi_env env, void* externalData, size_t byteLength, Finalizer finalizeCallback);

Returns a new Napi::ArrayBuffer instance.

New

Wraps the provided external data into a new Napi::ArrayBuffer instance.

The Napi::ArrayBuffer instance does not assume ownership for the data and expects it to be valid for the lifetime of the instance. The data can only be freed once the finalizeCallback is invoked to indicate that the Napi::ArrayBuffer has been released.

cpp template <typename Finalizer, typename Hint> static Napi::ArrayBuffer Napi::ArrayBuffer::New(napi_env env, void* externalData, size_t byteLength, Finalizer finalizeCallback, Hint* finalizeHint);

Returns a new Napi::ArrayBuffer instance.

Constructor

Initializes an empty instance of the Napi::ArrayBuffer class.

cpp Napi::ArrayBuffer::ArrayBuffer();

Constructor

Initializes a wrapper instance of an existing Napi::ArrayBuffer object.

cpp Napi::ArrayBuffer::ArrayBuffer(napi_env env, napi_value value);

ByteLength

cpp size_t Napi::ArrayBuffer::ByteLength() const;

Returns the length of the wrapped data, in bytes.

Data

cpp T* Napi::ArrayBuffer::Data() const;

Returns a pointer the wrapped data.