typed-array-reserve
v1.0.0
Published
Reserve capacity in a typed array: reuse it when long enough, grow it geometrically otherwise.
Maintainers
Readme
typed-array-reserve
Reserve capacity in a typed array: reuse it when long enough, grow it geometrically otherwise.
Installation
npm install typed-array-reserveUsage
import typedArrayReserve from "typed-array-reserve";
// Reuse buffers across frames, reallocating only when the count grows
let positions = new Float32Array(0);
function update(count) {
positions = typedArrayReserve(positions, count * 3);
}
// Append, keeping the previous values. Doubling trades memory for speed.
let indices = new Uint32Array(4);
let size = 0;
function push(index) {
indices = typedArrayReserve(indices, size + 1, true, 2);
indices[size++] = index;
}API
typedArrayReserve
- typedArrayReserve
- typedArrayReserve(array, length, [copy], [factor]) ⇒ TypedArray ⏏
- ~TypedArray : Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array
- typedArrayReserve(array, length, [copy], [factor]) ⇒ TypedArray ⏏
typedArrayReserve(array, length, [copy], [factor]) ⇒ TypedArray ⏏
Typed array of at least length elements: array when long enough, a new
array of the same type otherwise.
Kind: Exported function See: Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to algorithms (3rd ed.), §17.4 Dynamic tables. MIT Press.
| Param | Type | Default | Description |
| -------- | ----------------------------------------------------------------------------------- | ------------------ | -------------------------------------------------------------- |
| array | TypedArray | | |
| length | number | | |
| [copy] | boolean | false | Copy the values of array. |
| [factor] | number | 1.5 | Growth factor, above 1. Higher is faster and uses more memory. |
typedArrayReserve~TypedArray : Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array
Kind: inner typedef of typedArrayReserve
License
MIT. See license file.
