Skip to content

Commit

Permalink
doc: update Buffer.allocUnsafe description
Browse files Browse the repository at this point in the history
PR-URL: #48183
Fixes: #42821
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
sinkhaha authored and danielleadams committed Jul 6, 2023
1 parent 8512e64 commit 435b2c8
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -805,10 +805,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)`][], [`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).
`Buffer` instances created using [`Buffer.allocUnsafe()`][], [`Buffer.from(array)`][],
and [`Buffer.concat()`][] 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

0 comments on commit 435b2c8

Please sign in to comment.