![](/img/trans.png)
[英]nodejs request - toString failed - buffer size issue for big files (maxBufferSize)
[英]Buffer size in nodejs
// node v0.5.6 //
我假設nodejs可以在nodejs堆之外分配的最大緩沖區大小受可用系統內存量的限制。 雖然我有幾次免費內存,但我似乎無法在沒有崩潰節點的情況下接近這個限制。
致命錯誤: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;
不幸的是,您收到的錯誤消息有點誤導,但您有緩沖區溢出錯誤。
你的循環將一直運行直到cur == bcast,所以最后一個writeUInt32LE會寫一個超過緩沖區長度的數字。 將循環比較更改為“cur <bcast”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.