簡體   English   中英

JavaScript中的數組不能超過7741個元素

[英]Array could not more than 7741 elements in JavaScript

我正在使用Node.js。 我有以下javascript代碼。

var length=9980;
this.distance= [];//hold distance
this.cost= [];   //hold time cost   

 console.log("before create distance and cost arrays"); 
 console.log("length" + length);   
 for(var i=0; i < length;i++)
 {   
    console.log("creating cost : " + i );       
    this.distance[i] = new Array(length);
    this.cost[i] = new Array(length);
 }; 

這樣,我想創建2維數組

 distance, cost

如上圖所示。

有問題報告錯誤。

在此處輸入圖片說明

數組應該能夠容納數百萬個元素,但是會出現這種錯誤。

問題是什么? 我該如何運作?

我認為您遇到了節點的默認內存限制。

嘗試使用--max_old_space_size =標志添加正在運行的節點應用程序。

node --max_old_space_size=4096 app.js

根據http://prestonparry.com/articles/IncreaseNodeJSMemorySize/,該數字以兆字節為單位,因此應為您提供4GB的內存上限。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM