What's the maximum size of a Node.js Buffer

Joel picture Joel · Jan 23, 2012 · Viewed 26.9k times · Source

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

Or,

RangeError: "size" argument must not be larger than 2147483647 at Function.Buffer.allocUnsafe (buffer.js:209:3)

If I try to allocate a 1GB Buffer I get the same fatal Error,

var oneGigInBytes = 1073741824;
var my1GBuffer = new Buffer(oneGigInBytes); //Crash   

What is the maximum size of a Node.js Buffer class instance?

Answer

Vyacheslav Egorov picture Vyacheslav Egorov · Jan 23, 2012

Maximum length of a typed array in V8 is currently set to kSmiMaxValue which depending on the platform is either:

  • 1Gb - 1byte on 32-bit
  • 2Gb - 1byte on 64-bit

Relevant constant in the code is v8::internal::JSTypedArray::kMaxLength (source).

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.