[英]Buffer allocation in node.js
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? 如果我分配一个1024字节的缓冲区,并在其中有效存储128个字节,那么将在内存中分配多少字节?
According to the constructor doc: 根据构造函数doc:
new Buffer(size)# 新缓冲区(大小)#
size
Number Allocates a new buffer of size bytes. size
Number分配大小为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. 32位体系结构上的大小必须小于1,073,741,824
字节(1 GB)或64位体系结构上的大小必须小于2,147,483,648
字节(2 GB),否则会引发RangeError
。
Unlike ArrayBuffers, the underlying memory for buffers is not initialized . 与ArrayBuffers不同, 缓冲区的底层内存未初始化 。 So the contents of a newly created Buffer are unknown and could contain sensitive data. 因此,新创建的Buffer的内容未知,可能包含敏感数据。 Use buf.fill(0)
to initialize a buffer to zeroes. 使用buf.fill(0)
将缓冲区初始化为零。
It seem that the whole memory is allocated, but not zeroified. 似乎整个内存已分配,但未归零。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.