简体   繁体   中英

Bad_alloc when declaring array, seems enough memory

I'm coding to declare several large arrays and do manipulation with elements etc.

When the code gets to one section, declaring a temporary array, it throws up a bad_alloc after making about 1.8m columns.

Code is:

int** tempArray1= new int*[PHLengths[n-1]];

for(int i =0;i<PHLengths[n-1];i++) {

 tempArray1[i]=new int[PrimeDatL]; 

}

In the case being considered PrimeDatL ~417 and PHLengths[n-1]~3630140.

Ordinarily I would assume this is just a matter of not having enough RAM (as it happens it will be underfilled as currently defined so I COULD declare a dynamic array and fill/expand along the way) however when I keep an eye on computer resources it goes to about 3gb/5gb then gives the error.

The one subtlety here is that I am using ubuntu on virtualbox, so could this cause memory address issues? Is it naive to think this error only occurs when I'm completely out of RAM?

I also tried declaring it earlier in the program to see if there were memory issues along the way, same problem.

如果您使用的是32位计算机,则无论您实际拥有多少内存,都只能寻址大约4GB的内存,因此这可能就是为什么它在“ 3gb / 5gb”之间掉落的原因。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM