I run code below and get some strange output:
#include <iostream>
using namespace std;
int main()
{
for(int ll=1444; ll<1450; ++ll)
{
cout<<ll<<endl;
cout<<"###### 0 #######"<<endl;
int mtx[ll][ll];
cout<<"###### 1 #######"<<endl;
}
return 0;
}
The output is:
1444
###### 0 #######
###### 1 #######
1445
###### 0 #######
###### 1 #######
1446
###### 0 #######
###### 1 #######
1447
###### 0 #######
###### 1 #######
1448
###### 0 #######
Segmentation fault
I tried checked one by one with ll's value, when ll reaches 1448, segmentation fault does happen.
Then I changed the array from int to bool, problem disappears.
A calculation based on ll's value:
ll=1447, total space of array is 1447*1447*4 = 8375236 bytes = 8178.95 Kbytes
ll=1448, total space of array is 1448*1448*4 = 8386816 bytes = 8190.25 Kbytes
Could a possible reason be the size of this array is bigger than default page size? (How to check it in Ubunut 14.04..?)
BTW, tried with java and there is no problem.