什么是一个Node.js缓冲区的最大大小

根据Node.js缓冲区类文档缓冲区分配在V8堆的外部。

http://nodejs.org/docs/latest/api/buffers.html

原始数据存储在Buffer类的实例中。 缓冲区类似于整数数组,但对应于V8堆外部的原始内存分配。 缓冲区不能resize。

我需要读一个大文件(大于1GB),并尝试使用fd.readPath(),但从V8得到一个致命的错误,因为该文件大于1GB。

FATAL ERROR: v8::Object::SetIndexedPropertiesToExternalArrayData() length exceeds max acceptable value 

这是由Googlelogging的。 http://code.google.com/p/v8/issues/detail?id=847

我想我会使用一个缓冲区,我正在运行一个64位版本的节点0.6.7,所以我的堆应该能够处理大文件。

 $ file `which node` /usr/local/bin/node: Mach-O 64-bit executable x86_64 $ 

但是,如果我尝试分配一个1GB的缓冲区,我得到同样的致命错误的V8。

 var oneGigInBytes = 1073741824; var my1GBuffer = new Buffer(oneGigInBytes); //Crash //var mySmallerBuffer = new Buffer(oneGigInBytes-1); //Works console.log("done"); 

如果一个缓冲区被分配到V8堆的外部,我想我可以分配一个大于1GB限制的缓冲区大小,但是上面的代码与readPath()打印的是相同的确切错误。 注释掉my1GBuffer实例并取消注释mySmallerBuffer的工作,所以看起来1GB是有限制的。

什么是Node.js缓冲区类实例的最大大小? 它是封顶在1GB? 我目前的解决方法是使用读取stream和和fs.pipe()。

 var fs = require('fs'); process.chdir("/Users/joel/Desktop/testFiles/"); var stream = fs.createReadStream('./test1GB_File', { bufferSize: 64 * 1024 }); stream.pipe(response); 

最大长度是1GB – 1个字节。 代码中的相关常量是v8::internal::ExternalArray::kMaxLength

https://github.com/v8/v8/blob/c8bf5c35e431d4029e084024501863a4cf907882/src/objects.h#L4647-L4648

似乎目前的最大缓冲区大小是2147483647字节,又名2.147GB

来源: https : //stackoverflow.com/a/44994896/3973137 (和我自己的代码)