I want to use a buffer to store a sparse index. If I allocate a buffer of, say, 1024 bytes, and store effectively 128 bytes in it, how many bytes will be allocated in memory?
According to the constructor doc:
new Buffer(size)#
size Number
Allocates a new buffer of size bytes. size must be less than 1,073,741,824 bytes (1 GB) on 32 bits architectures or 2,147,483,648 bytes (2 GB) on 64 bits architectures, otherwise a RangeError is thrown.
Unlike ArrayBuffers, the underlying memory for buffers is not initialized. So the contents of a newly created Buffer are unknown and could contain sensitive data. Use buf.fill(0) to initialize a buffer to zeroes.
It seem that the whole memory is allocated, but not zeroified.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With