Node.js Buffer Allocation: Pools & Memory Safety #51
Replies: 2 comments 1 reply
|
Hi @ishtms I've a little doubt you've written here that Buffer.alloc() can use internal 8KB buffer pool but in the offical node documentation it is said that it will never use the intern poll https://nodejs.org/api/buffer.html#static-method-bufferallocunsafesize, can you help me figure this out? |
|
Your reading of the Node docs is correct: The distinction I would make in the article is: So if the text says The memory-safety point still holds, but it belongs to The practical guidance is: // safest for fresh writable memory
const buf = Buffer.alloc(size)
// faster, but only safe if every byte is overwritten before reading/sending
const buf = Buffer.allocUnsafe(size)For sensitive data, I would prefer Official docs also describe this difference here: https://nodejs.org/api/buffer.html |
Uh oh!
There was an error while loading. Please reload this page.
Node.js Buffer Allocation: Pools & Memory Safety
How Buffer.alloc, Buffer.allocUnsafe, Buffer.from, slab pooling, and large Buffer allocation affect memory safety and performance in Node.js.
https://www.thenodebook.com/buffers/allocation-patterns
All reactions