--zero-fill-buffers 命令行选项


使用 --zero-fill-buffers 命令行选项时, new Buffer(size)Buffer.allocUnsafe()Buffer.allocUnsafeSlow()new SlowBuffer(size) 返回的 Buffer 在创建时会用 0 填充。

$ node --zero-fill-buffers
> Buffer.allocUnsafe(5);
<Buffer 00 00 00 00 00>

Node.js can be started using the --zero-fill-buffers command line option to cause all newly allocated Buffer instances to be zero-filled upon creation by default, including buffers returned by new Buffer(size), Buffer.allocUnsafe(), Buffer.allocUnsafeSlow(), and new SlowBuffer(size). Use of this flag can have a significant negative impact on performance. Use of the --zero-fill-buffers option is recommended only when necessary to enforce that newly allocated Buffer instances cannot contain old data that is potentially sensitive.

$ node --zero-fill-buffers
> Buffer.allocUnsafe(5);
<Buffer 00 00 00 00 00>