Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: document Buffer.concat may use internal pool #35541

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions doc/api/buffer.md
Expand Up @@ -394,9 +394,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 @@ -573,6 +573,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 @@ -3321,6 +3324,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