Skip to content

Commit

Permalink
doc: document Buffer.concat may use internal pool
Browse files Browse the repository at this point in the history
PR-URL: #35541
Refs: #32703
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Harshitha K P <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
  • Loading branch information
puzpuzpuz authored and MylesBorins committed Oct 14, 2020
1 parent 16c17dd commit 0c87776
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ A `TypeError` will be thrown if `size` is not a number.
The `Buffer` module pre-allocates an internal `Buffer` instance of
size [`Buffer.poolSize`][] that is used as a pool for the fast allocation of new
`Buffer` instances created using [`Buffer.allocUnsafe()`][],
[`Buffer.from(array)`][], and the deprecated `new Buffer(size)` constructor only
when `size` is less than or equal to `Buffer.poolSize >> 1` (floor of
[`Buffer.poolSize`][] divided by two).
[`Buffer.from(array)`][], [`Buffer.concat()`][], and the deprecated
`new Buffer(size)` constructor only when `size` is less than or equal
to `Buffer.poolSize >> 1` (floor of [`Buffer.poolSize`][] divided by two).

Use of this pre-allocated internal memory pool is a key difference between
calling `Buffer.alloc(size, fill)` vs. `Buffer.allocUnsafe(size).fill(fill)`.
Expand Down Expand Up @@ -560,6 +560,9 @@ console.log(bufA.length);
// Prints: 42
```

`Buffer.concat()` may also use the internal `Buffer` pool like
[`Buffer.allocUnsafe()`][] does.

### Static method: `Buffer.from(array)`
<!-- YAML
added: v5.10.0
Expand Down Expand Up @@ -3276,6 +3279,7 @@ introducing security vulnerabilities into an application.
[`Buffer.alloc()`]: #buffer_static_method_buffer_alloc_size_fill_encoding
[`Buffer.allocUnsafe()`]: #buffer_static_method_buffer_allocunsafe_size
[`Buffer.allocUnsafeSlow()`]: #buffer_static_method_buffer_allocunsafeslow_size
[`Buffer.concat()`]: #buffer_static_method_buffer_concat_list_totallength
[`Buffer.from(array)`]: #buffer_static_method_buffer_from_array
[`Buffer.from(arrayBuf)`]: #buffer_static_method_buffer_from_arraybuffer_byteoffset_length
[`Buffer.from(buffer)`]: #buffer_static_method_buffer_from_buffer
Expand Down

0 comments on commit 0c87776

Please sign in to comment.