allocate()

in modules/core/src/utils/typed-array-manager.js [12:36]


  allocate(typedArray, count, {size = 1, type, padding = 0, copy = false, initialize = false}) {
    const Type = type || (typedArray && typedArray.constructor) || Float32Array;

    const newSize = count * size + padding;
    if (ArrayBuffer.isView(typedArray)) {
      if (newSize <= typedArray.length) {
        return typedArray;
      }
      if (newSize * typedArray.BYTES_PER_ELEMENT <= typedArray.buffer.byteLength) {
        return new Type(typedArray.buffer, 0, newSize);
      }
    }

    const newArray = this._allocate(Type, newSize, initialize);

    if (typedArray && copy) {
      newArray.set(typedArray);
    } else if (!initialize) {
      // Hack - always initialize the first 4 elements. NaNs crashe the Attribute validation
      newArray.fill(0, 0, 4);
    }

    this._release(typedArray);
    return newArray;
  }