2

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.

LCB
  • 971
  • 9
  • 22

1 Answers1

2

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'
Pall Arpad
  • 1,625
  • 16
  • 20