// node v0.5.6 //
I assume the max buffer size that nodejs can allocate outside of the nodejs heap is limited by the amount of available system memory. I have several gigs of free memory though and I can’t seem to get even close to that limit without crashing node.
FATAL ERROR: JS Allocation failed – process out of memory
function bigArray(){
// each ip could be 10 digits long, therefore,
// 10 * (bcast-cur) = size of Buffer.
// does that also mean size in bytes?
var cur = 167772160;
var bcast = 184549375;
var addresses = new Buffer((bcast-cur)*10);
var offset = 0;
while (cur <= bcast){
cur += 1;
addresses.writeUInt32LE(cur,offset);
offset+=10;
}
return addresses;
};
var ba = bigArray();
It crashes on line 235 of Buffer.js in the node library at this block:
if (this.length > Buffer.poolSize) {
// Big buffer, just alloc one.
this.parent = new SlowBuffer(this.length); //crash here
this.offset = 0;
The error message that you are getting is a bit misleading unfortunately, but you have a buffer overflow error.
Your loop will run until cur == bcast, so the very last writeUInt32LE will write a number past the length of the buffer. Change your loop comparison to “cur < bcast”.