Skip to content

Unclear docs on copying/sharing memory for Buffer.from(arrayBuffer) #10770

Description

@zbjornson
  • Version: v7.4.0
  • Subsystem: docs (buffer)

The docs for Buffer.from(arrayBuffer) use the word copy/copying:

  • byteOffset Where to start copying from arrayBuffer. Default: 0
  • length How many bytes to copy from arrayBuffer. Default: arrayBuffer.length - byteOffset

But as far as I can tell, it always references a subarray and never copies.

The line below it:

When passed a reference to the .buffer property of a TypedArray instance, the newly created Buffer will share the same allocated memory as the TypedArray.

is also confusing -- I think that's meant as an example to emphasize the point that it's shared memory, but to me it sounds like there's a situation when it would copy and not share (e.g. Buffer.from(new ArrayBuffer(8)).

Trivial change but wanted to make sure my understanding was correct before submitting a PR. Something like: "byteOffset - element to begin at", "length - number of elements to include" and adding "For example" to the "when passed a reference..." bit.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.docIssues and PRs related to Node.js documentation.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions