Reputation: 1050
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
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
Buffer.allocUnsafe()
method uses this (if its size allows) for 'fast' allocation Buffer.allocUnsafeSlow()
don't use this pool, that's why it's called 'slow' Upvotes: 2