ensureCapacity Method
Ensure that TypedArrayBuilder.capacity is at least equal to newCapacity
.
This is used internally by methods like TypedArrayBuilder.push and TypedArrayBuilder.append to ensure the array has room for the element(s) to be added.
It can also be useful when you know you intend to add some number of additional elements, to minimize reallocations.
If newCapacity
is not greater than the current TypedArrayBuilder.capacity, this function does nothing.
Otherwise, it allocates a new TypedArray
with room for newCapacity * growthFactor
elements, and copies the contents of the previous TypedArray
into it.
TypedArrayBuilder.length remains unchanged; TypedArrayBuilder.capacity reflects the size of the new TypeArray.
ensureCapacity(newCapacity: number): number
Parameter | Type | Description |
---|---|---|
newCapacity | number |
Returns - number
Defined in
Last Updated: 25 April, 2024