The Napi::TypedArrayOf
class corresponds to the various
JavaScript TypedArray
classes.
The common JavaScript TypedArray
types are pre-defined for each of use:
typedef Napi::TypedArrayOf<int8_t> Int8Array;
typedef Napi::TypedArrayOf<uint8_t> Uint8Array;
typedef Napi::TypedArrayOf<int16_t> Int16Array;
typedef Napi::TypedArrayOf<uint16_t> Uint16Array;
typedef Napi::TypedArrayOf<int32_t> Int32Array;
typedef Napi::TypedArrayOf<uint32_t> Uint32Array;
typedef Napi::TypedArrayOf<float> Float32Array;
typedef Napi::TypedArrayOf<double> Float64Array;
The one exception is the Uint8ClampedArray
which requires explicit
initialization:
Uint8Array::New(env, length, napi_uint8_clamped_array)
Note that while it's possible to create a "clamped" array the clamping behavior is only applied in JavaScript.
Allocates a new Napi::TypedArray
instance with a given length. The underlying
Napi::ArrayBuffer
is allocated automatically to the desired number of elements.
The array type parameter can normally be omitted (because it is inferred from the template parameter T), except when creating a "clamped" array.
static Napi::TypedArrayOf Napi::TypedArrayOf::New(napi_env env,
size_t elementLength,
napi_typedarray_type type);
[in] env
: The environment in which to create theNapi::TypedArrayOf
instance.[in] elementLength
: The length to be allocated, in elements.[in] type
: The type of array to allocate (optional).
Returns a new Napi::TypedArrayOf
instance.
Wraps the provided Napi::ArrayBuffer
into a new Napi::TypedArray
instance.
The array type
parameter can normally be omitted (because it is inferred from
the template parameter T
), except when creating a "clamped" array.
static Napi::TypedArrayOf Napi::TypedArrayOf::New(napi_env env,
size_t elementLength,
Napi::ArrayBuffer arrayBuffer,
size_t bufferOffset,
napi_typedarray_type type);
[in] env
: The environment in which to create theNapi::TypedArrayOf
instance.[in] elementLength
: The length to array, in elements.[in] arrayBuffer
: The backingNapi::ArrayBuffer
instance.[in] bufferOffset
: The offset into theNapi::ArrayBuffer
where the array starts, in bytes.[in] type
: The type of array to allocate (optional).
Returns a new Napi::TypedArrayOf
instance.
Initializes an empty instance of the Napi::TypedArrayOf
class.
Napi::TypedArrayOf::TypedArrayOf();
Initializes a wrapper instance of an existing Napi::TypedArrayOf
object.
Napi::TypedArrayOf::TypedArrayOf(napi_env env, napi_value value);
[in] env
: The environment in which to create theNapi::TypedArrayOf
object.[in] value
: TheNapi::TypedArrayOf
reference to wrap.
T& Napi::TypedArrayOf::operator [](size_t index);
- `[in] index: The element index into the array.
Returns the element found at the given index.
const T& Napi::TypedArrayOf::operator [](size_t index) const;
- `[in] index: The element index into the array.
Returns the element found at the given index.
T* Napi::TypedArrayOf::Data() const;
Returns a pointer into the backing Napi::ArrayBuffer
which is offset to point to the
start of the array.
const T* Napi::TypedArrayOf::Data() const
Returns a pointer into the backing Napi::ArrayBuffer
which is offset to point to the
start of the array.