Skip to content

Commit

Permalink
doc: clarify memory sharing behavior of buffer ctor
Browse files Browse the repository at this point in the history
* Clarify that memory is always shared and never copied.
* Fix wording that sounded like ArrayBuffer has a buffer property.

PR-URL: nodejs/node#10778
Ref: nodejs/node#10770
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
zbjornson authored and andrew749 committed Jul 19, 2017
1 parent ac0f60d commit 71f2519
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,16 @@ deprecated: v6.0.0
> [`Buffer.from(arrayBuffer[, byteOffset [, length]])`][`Buffer.from(arrayBuffer)`]
> instead.
* `arrayBuffer` {ArrayBuffer} The `.buffer` property of a [`TypedArray`] or
[`ArrayBuffer`]
* `byteOffset` {Integer} Where to start copying from `arrayBuffer`. **Default:** `0`
* `length` {Integer} How many bytes to copy from `arrayBuffer`.
* `arrayBuffer` {ArrayBuffer} An [`ArrayBuffer`] or the `.buffer` property of a
[`TypedArray`].
* `byteOffset` {Integer} Index of first byte to expose. **Default:** `0`
* `length` {Integer} Number of bytes to expose.
**Default:** `arrayBuffer.length - byteOffset`

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`].
This creates a view of the [`ArrayBuffer`] without copying the underlying
memory. For example, 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`].

The optional `byteOffset` and `length` arguments specify a memory range within
the `arrayBuffer` that will be shared by the `Buffer`.
Expand Down Expand Up @@ -726,15 +727,16 @@ A `TypeError` will be thrown if `array` is not an `Array`.
added: v5.10.0
-->

* `arrayBuffer` {ArrayBuffer} The `.buffer` property of a [`TypedArray`] or
[`ArrayBuffer`]
* `byteOffset` {Integer} Where to start copying from `arrayBuffer`. **Default:** `0`
* `length` {Integer} How many bytes to copy from `arrayBuffer`.
* `arrayBuffer` {ArrayBuffer} An [`ArrayBuffer`] or the `.buffer` property of a
[`TypedArray`].
* `byteOffset` {Integer} Index of first byte to expose. **Default:** `0`
* `length` {Integer} Number of bytes to expose.
**Default:** `arrayBuffer.length - byteOffset`

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`].
This creates a view of the [`ArrayBuffer`] without copying the underlying
memory. For example, 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`].

Example:

Expand Down

0 comments on commit 71f2519

Please sign in to comment.