Node.js缓冲区的最大大小是多少 [英] What's the maximum size of a Node.js Buffer
问题描述
读取文件太大而无法放入缓冲区时出现致命错误.
I got a fatal error reading a file was too big to fit in a buffer.
FATAL ERROR: v8::Object::SetIndexedPropertiesToExternalArrayData() length exceeds max acceptable value
或者
RangeError:大小"参数不得大于2147483647 在Function.Buffer.allocUnsafe(buffer.js:209:3)
RangeError: "size" argument must not be larger than 2147483647 at Function.Buffer.allocUnsafe (buffer.js:209:3)
如果我尝试分配1GB缓冲区,则会遇到同样的致命错误,
If I try to allocate a 1GB Buffer I get the same fatal Error,
var oneGigInBytes = 1073741824;
var my1GBuffer = new Buffer(oneGigInBytes); //Crash
Node.js Buffer类实例的最大大小是多少?
What is the maximum size of a Node.js Buffer class instance?
推荐答案
V8中类型化数组的最大长度当前设置为kSmiMaxValue
,具体取决于平台是:
Maximum length of a typed array in V8 is currently set to kSmiMaxValue
which depending on the platform is either:
- 1Gb-32位上1字节
- 2Gb-64位上1字节
代码中的相关常量为v8::internal::JSTypedArray::kMaxLength
(
Relevant constant in the code is v8::internal::JSTypedArray::kMaxLength
(source).
V8团队正在努力在64位平台上进一步提高此功能,在该平台上,当前ArrayBuffer
个对象可以达到Number.MAX_SAFE_INTEGER
个大对象(2 ** 53-1).参见错误4153 .
V8 team is working on increasing this even further on 64-bit platforms, where currently ArrayBuffer
objects can be up to Number.MAX_SAFE_INTEGER
large (2**53 - 1). See bug 4153.
这篇关于Node.js缓冲区的最大大小是多少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!