Skip to content

Fast Allocation of ArrayBuffer with maxByteLength #53680

Open
@ronag

Description

@ronag

Currently we have an optimization which turns off zero fill of ArrayBuffers during allocation through the Buffer.allocUnsafeSlow method:

let zeroFill = getZeroFillToggle();
function createUnsafeBuffer(size) {
  zeroFill[0] = 0;
  try {
    return new FastBuffer(size);
  } finally {
    zeroFill[0] = 1;
  }
}

This can be used to quickly allocate ArrayBuffers:

const arrayBuffer = Buffer.allocateUnsafeSlow(size).buffer

The problem is that this does not allow allocating ArrayBuffers with a specified maxByteLength:

const arrayBuffer = new ArrayBuffer(size, { maxByteLength: capacity })

Could we add some way to perform the allocation similarly? Maybe an option to Buffer.allocateUnsafeSlow?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions