// node v0.5.6 //
我认为nodejs可以在nodejs堆之外分配的最大缓冲区大小受可用系统内存量的限制。尽管我有几GB的空闲内存,但似乎无法接近极限而不使node崩溃。
致命错误:JS分配失败-进程内存不足
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();
它在节点库中的Buffer.js文件的235行崩溃,具体表现为以下代码块:
if (this.length > Buffer.poolSize) {
// Big buffer, just alloc one.
this.parent = new SlowBuffer(this.length); //crash here
this.offset = 0;