Skip to content

Conversation

@ChALkeR
Copy link
Member

@ChALkeR ChALkeR commented Oct 29, 2025

Do not needlessly promote allocUnsafe.

Dates back to #4682

While the intention was to make allocUnsafe a code replacement for Buffer constructor, it has also been to let users use Buffer.alloc by default and/or when they are not sure, and optimize with allocUnsafe only when needed and when they ensured that nothing gets leaked (which often requires extra actions e.g. error handling or guards against race conditions)

Most documentation methods should use Buffer.alloc instead of Buffer.allocUnsafe by default in examples

This aligns documentation accents internally with the wording in this intent:

node/doc/api/buffer.md

Lines 5066 to 5067 in dec0213

> Stability: 0 - Deprecated: Use [`Buffer.alloc()`][] instead (also see
> [`Buffer.allocUnsafe()`][]).

And https://nodejs.org/docs/latest/api/buffer.html#bufferfrom-bufferalloc-and-bufferallocunsafe

@nodejs-github-bot nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. doc Issues and PRs related to the documentations. labels Oct 29, 2025
@ChALkeR ChALkeR changed the title doc: do not needlessly promote allocUnsafe doc: replace allocUnsafe with alloc in examples Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

buffer Issues and PRs related to the buffer subsystem. doc Issues and PRs related to the documentations.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants