File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 9494> Node.js
9595
96961 . [ package.json 中,版本前的符号 ~ 和 ^ 有什么区别?] ( ./contents/node/packageJSON.md )
97+ 2 . [ Node.js 中的 Buffer 最大容量限制是多少?] ( ./contents/node/buffer.md )
9798
9899- todo ...
Original file line number Diff line number Diff line change 1+ ## 问题:Node.js 中的 Buffer 最大容量限制是多少?
2+
3+ 读取的文件太大,无法分配到 buffer,并得到了如下的报错
4+
5+ ``` js
6+ FATAL ERROR : v8:: Object :: SetIndexedPropertiesToExternalArrayData () length exceeds max acceptable value
7+ ```
8+
9+ RangeError: "size" argument must not be larger than 2147483647 at Function.Buffer.allocUnsafe (buffer.js:209:3)
10+
11+ 如果我试图分配一个 1GB 的 ` buffer ` ,会得到同样的错误。
12+
13+ ``` js
14+ var oneGigInBytes = 1073741824 ;
15+ var my1GBuffer = new Buffer (oneGigInBytes); // Crash
16+ ```
17+
18+ 那么 ` Node.js ` 的 ` Buffer ` 实例的最大容量限制是多少?
19+
20+ ## 答案
21+
22+ 在 ` V8 ` 中,目前 ` 类型化数组 ` (typed array) 的最大容量被设置为 ` kSmiMaxValue ` ,根据平台的不同,如下:
23+
24+ - 1Gb - 1byte on 32-bit
25+ - 2Gb - 1byte on 64-bit
26+
27+ 代码中的常数是 ` v8::internal::JSTypedArray::kMaxLength ` ([ 源代码] ( https://github.com/v8/v8/blob/d56ee2e3df56ad13e5d2f2d790faaffc3a493aee/src/objects/js-array-buffer.h#L181 ) )
28+
29+ ``` js
30+
31+ ```
32+
33+ ` V8 ` 团队正在努力在 ` 64位 ` 平台上进一步提高其容量限制,目前 ` ArrayBuffer ` 对象可以达到 ` Number.MAX_SAFE_INTEGER大 ` (2** 53-1)。[ 参见Bug 4153] ( https://bugs.chromium.org/p/v8/issues/detail?id=4153 ) 。
34+
35+ > 问题来源:[ https://stackoverflow.com/questions/8974375/whats-the-maximum-size-of-a-node-js-buffer ] ( https://stackoverflow.com/questions/8974375/whats-the-maximum-size-of-a-node-js-buffer )
You can’t perform that action at this time.
0 commit comments