diff options
author | Harshitha KP <harshi46@in.ibm.com> | 2020-04-07 14:32:04 +0300 |
---|---|---|
committer | Beth Griggs <Bethany.Griggs@uk.ibm.com> | 2020-04-14 13:03:56 +0300 |
commit | a7c75f956f05be3dec30cde4091865dec79349be (patch) | |
tree | 713d7034b57897dd8a32fc5c646faa027d7313bd /doc/api | |
parent | 63f0dd1ab9a47d1682f48e2f68cfbc583d00aa3e (diff) |
doc: document `buffer.from` returns internal pool buffer
Fixes: https://github.com/nodejs/node/issues/22139
Co-authored-by: Mritunjay Goutam <mritunjaygoutam2204@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/32703
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'doc/api')
-rw-r--r-- | doc/api/buffer.md | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 28f306f09ab..b839f0cebad 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -379,9 +379,10 @@ 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()`][] 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 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)`. @@ -571,6 +572,9 @@ const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]); A `TypeError` will be thrown if `array` is not an `Array` or other type appropriate for `Buffer.from()` variants. +`Buffer.from(array)` and [`Buffer.from(string)`][] may also use the internal +`Buffer` pool like [`Buffer.allocUnsafe()`][] does. + ### Class Method: `Buffer.from(arrayBuffer[, byteOffset[, length]])` <!-- YAML added: v5.10.0 @@ -2733,10 +2737,11 @@ to one of these new APIs.* uninitialized, the allocated segment of memory might contain old data that is potentially sensitive. -`Buffer` instances returned by [`Buffer.allocUnsafe()`][] *may* be allocated off -a shared internal memory pool if `size` is less than or equal to half -[`Buffer.poolSize`][]. Instances returned by [`Buffer.allocUnsafeSlow()`][] -*never* use the shared internal memory pool. +`Buffer` instances returned by [`Buffer.allocUnsafe()`][] and +[`Buffer.from(array)`][] *may* be allocated off a shared internal memory pool +if `size` is less than or equal to half [`Buffer.poolSize`][]. Instances +returned by [`Buffer.allocUnsafeSlow()`][] *never* use the shared internal +memory pool. ### The `--zero-fill-buffers` command line option <!-- YAML |