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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.