LCB
LCB

Reputation: 1050

What is Shared Internal Memory Pool in node.js

The description about Buffer.allocUnsafe() and Buffer.allocUnSafeSlow() in the documentation of node.js is:

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.

I can't understand the meaning of the shared internal memory pool, can anyone help me and give me an explanation? Thank you so much.

Upvotes: 2

Views: 513

Answers (1)

Pall Arpad
Pall Arpad

Reputation: 1898

Node.js Buffer module pre-allocates an internal Buffer instance of size Buffer.poolSize that is used as a "Pool" for fast allocation

  • the Buffer.allocUnsafe() method uses this (if its size allows) for 'fast' allocation
  • the Buffer.allocUnsafeSlow() don't use this pool, that's why it's called 'slow'

Upvotes: 2

Related Questions