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?
-
What are you calling a buffer ? a string ? a byte array ?Remy Grandin– Remy Grandin2015-09-28 08:15:13 +00:00Commented Sep 28, 2015 at 8:15
-
nodejs.org/api/buffer.htmlGaël Barbin– Gaël Barbin2015-09-28 08:16:11 +00:00Commented Sep 28, 2015 at 8:16
-
1that may be not a part of v8 but of node jsGaël Barbin– Gaël Barbin2015-09-28 08:16:56 +00:00Commented Sep 28, 2015 at 8:16
Add a comment
|
1 Answer
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.
1 Comment
Gaël Barbin
Yes, I have read that, but I was thinking of a possible memory allocation optimisation. If not I will do my own.