Function expandBuffer

  • Expands the size of an existing ArrayBuffer to accommodate additional data if necessary.

    This function creates a new ArrayBuffer with a size that is at least as large as the required size. The buffer's size grows exponentially (doubles) to minimize reallocations and improve performance for large data handling. The existing data from the old buffer is copied into the new buffer.

    Returns

    A new ArrayBuffer with enough space to accommodate the required size.

    Example

    let buffer = new ArrayBuffer(1024);
    const updatedBuffer = expandBuffer(buffer, 2048);
    console.log(updatedBuffer.byteLength); // 2048 or larger (depending on initial size and required size)

    Parameters

    • currentBuffer: ArrayBuffer

      The current ArrayBuffer that needs to be expanded.

    • requiredSize: number

      The minimum size required for the buffer.

    Returns ArrayBuffer

Generated using TypeDoc