Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

node.js

v8

I got a fatal error reading a file that 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?

like image 659
Joel Avatar asked Jan 23 '12 15:01

Joel


People also ask

What is the maximum buffer size?

The upper limit for the maximum buffer size is 32768␠bytes (32␠KB). The lower limit is 580 bytes in general and in addition, if the interface is up and running <current MTU + header size> . The header space is typically 4 bytes.

What is buffer size in JavaScript?

For buffers containing UTF8 encoded strings, the buffer's length is equivalent to the length of the string. For example, if you read a text file from the file system using fs , the resulting buffer's length is the same as the number of characters in the text file.

What is a node JS buffer?

Buffers in Node. js is used to perform operations on raw binary data. Generally, Buffer refers to the particular memory location in memory. Buffer and array have some similarities, but the difference is array can be any type, and it can be resizable. Buffers only deal with binary data, and it can not be resizable.

Is node js no buffering?

No Buffering − Node. js applications never buffer any data. These applications simply output the data in chunks. Pure JavaScript does not handle straight binary data very well, though JavaScript is Unicode friendly.


1 Answers

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.

like image 56
Vyacheslav Egorov Avatar answered Sep 18 '22 05:09

Vyacheslav Egorov