Skip to content

Commit 041f6cd

Browse files
Trotttargos
authored andcommitted
doc: improve Buffer.allocUnsafeSlow() and related
* Fixed "cleanup" being misused as a verb * "Use of Foo should only be used" construction changed to "Foo should only be used..." * Otherwise-unmentioned "`Persistent`" changed to more understandable "persistent" * remove an instance of unnecessary italics * wrap at 80 characters Change all "initialize a...instance to zeroes" to say "with zeroes" instead. Previously, both formulations appeared. PR-URL: #19742 Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 4df3377 commit 041f6cd

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

doc/api/buffer.md

+15-14
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ Prior to Node.js 8.0.0, the underlying memory for `Buffer` instances
434434
created in this way is *not initialized*. The contents of a newly created
435435
`Buffer` are unknown and *may contain sensitive data*. Use
436436
[`Buffer.alloc(size)`][`Buffer.alloc()`] instead to initialize a `Buffer`
437-
to zeroes.
437+
with zeroes.
438438

439439
```js
440440
const buf = new Buffer(10);
@@ -550,7 +550,7 @@ thrown. A zero-length `Buffer` will be created if `size` is 0.
550550
The underlying memory for `Buffer` instances created in this way is *not
551551
initialized*. The contents of the newly created `Buffer` are unknown and
552552
*may contain sensitive data*. Use [`Buffer.alloc()`] instead to initialize
553-
`Buffer` instances to zeroes.
553+
`Buffer` instances with zeroes.
554554

555555
```js
556556
const buf = Buffer.allocUnsafe(10);
@@ -593,20 +593,20 @@ thrown. A zero-length `Buffer` will be created if `size` is 0.
593593

594594
The underlying memory for `Buffer` instances created in this way is *not
595595
initialized*. The contents of the newly created `Buffer` are unknown and
596-
*may contain sensitive data*. Use [`buf.fill(0)`][`buf.fill()`] to initialize such
597-
`Buffer` instances to zeroes.
596+
*may contain sensitive data*. Use [`buf.fill(0)`][`buf.fill()`] to initialize
597+
such `Buffer` instances with zeroes.
598598

599599
When using [`Buffer.allocUnsafe()`] to allocate new `Buffer` instances,
600-
allocations under 4KB are, by default, sliced from a single pre-allocated
601-
`Buffer`. This allows applications to avoid the garbage collection overhead of
602-
creating many individually allocated `Buffer` instances. This approach improves
603-
both performance and memory usage by eliminating the need to track and cleanup as
604-
many `Persistent` objects.
600+
allocations under 4KB are sliced from a single pre-allocated `Buffer`. This
601+
allows applications to avoid the garbage collection overhead of creating many
602+
individually allocated `Buffer` instances. This approach improves both
603+
performance and memory usage by eliminating the need to track and clean up as
604+
many persistent objects.
605605

606606
However, in the case where a developer may need to retain a small chunk of
607607
memory from a pool for an indeterminate amount of time, it may be appropriate
608-
to create an un-pooled `Buffer` instance using `Buffer.allocUnsafeSlow()` then
609-
copy out the relevant bits.
608+
to create an un-pooled `Buffer` instance using `Buffer.allocUnsafeSlow()` and
609+
then copying out the relevant bits.
610610

611611
```js
612612
// Need to keep around a few small chunks of memory
@@ -625,8 +625,8 @@ socket.on('readable', () => {
625625
});
626626
```
627627

628-
Use of `Buffer.allocUnsafeSlow()` should be used only as a last resort *after*
629-
a developer has observed undue memory retention in their applications.
628+
`Buffer.allocUnsafeSlow()` should be used only as a last resort after a
629+
developer has observed undue memory retention in their applications.
630630

631631
A `TypeError` will be thrown if `size` is not a number.
632632

@@ -2464,7 +2464,8 @@ thrown. A zero-length `Buffer` will be created if `size` is 0.
24642464

24652465
The underlying memory for `SlowBuffer` instances is *not initialized*. The
24662466
contents of a newly created `SlowBuffer` are unknown and may contain sensitive
2467-
data. Use [`buf.fill(0)`][`buf.fill()`] to initialize a `SlowBuffer` to zeroes.
2467+
data. Use [`buf.fill(0)`][`buf.fill()`] to initialize a `SlowBuffer` with
2468+
zeroes.
24682469

24692470
```js
24702471
const { SlowBuffer } = require('buffer');

0 commit comments

Comments
 (0)