Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's the maximum size of a Node.js Buffer
    primarykey
    data
    text
    <p>According to the Node.js Buffer class documentation Buffers are allocated outside of the V8 heap.</p> <p><a href="http://nodejs.org/docs/latest/api/buffers.html">http://nodejs.org/docs/latest/api/buffers.html</a></p> <blockquote> <p>Raw data is stored in instances of the Buffer class. A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. A Buffer cannot be resized.</p> </blockquote> <p>I needed to read a large file (greater than 1GB) and tried to use fd.readPath() but got a fatal error from V8 because the file was greater that 1GB. </p> <pre><code>FATAL ERROR: v8::Object::SetIndexedPropertiesToExternalArrayData() length exceeds max acceptable value </code></pre> <p>This was documented by Google. <a href="http://code.google.com/p/v8/issues/detail?id=847">http://code.google.com/p/v8/issues/detail?id=847</a></p> <p>I figured I'd use a Buffer and I'm running a 64 bit version of node 0.6.7 so my heap should be able to handle large files.</p> <pre><code>$ file `which node` /usr/local/bin/node: Mach-O 64-bit executable x86_64 $ </code></pre> <p>However if I try to allocate a 1GB Buffer I get the same fatal Error out of V8.</p> <pre><code>var oneGigInBytes = 1073741824; var my1GBuffer = new Buffer(oneGigInBytes); //Crash //var mySmallerBuffer = new Buffer(oneGigInBytes-1); //Works console.log("done"); </code></pre> <p>If a Buffer was allocated outside of the V8 heap I figured I'd be able to allocate a buffer size greater than the 1GB limit but the code above prints the same exact error as readPath(). Commenting out the my1GBuffer instance and uncommenting mySmallerBuffer works so it appears 1GB is the limit.</p> <p>What is the maximum size of a Node.js Buffer class instance? Is it capped at 1GB? My current workaround is to use use a read stream and and fs.pipe().</p> <pre><code>var fs = require('fs'); process.chdir("/Users/joel/Desktop/testFiles/"); var stream = fs.createReadStream('./test1GB_File', { bufferSize: 64 * 1024 }); stream.pipe(response); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload