LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Segmentation fault (core dumped) (http://www.linuxquestions.org/questions/programming-9/segmentation-fault-core-dumped-820295/)

mayankladoia 07-16-2010 07:20 PM

Segmentation fault (core dumped)
 
I have following array deceleration in my file:

vector< vector<short int> > arr;
vector< vector<short int> > arr1;
vector< vector<short int> > temp;
vector<short int> n;
vector< vector< short int> > ind;
vector<short int> a;
vector< vector<short int> >f;

size of array is defined dynamically as:

arr.resize(x,vector<short int>(x,0));
arr1.resize(x,vector<short int>(x,0));
temp.resize(x,vector<short int>(x,0));
ind.resize(x,vector<short int>(x,0));
f.resize(3,vector<short int>(x*2,0));
n.resize(x);
a.resize(x);


x is inputted by the user. If the size of x is 1000 program works fine if it goes beyond 2000 I get the following error:

Segmentation fault (core dumped)

according to my calculation memory size req by my program is around

2000*2000 - by 2D array
2 byte by short int

so it is 2000*2000*2 = 8000000 Bytes = 7812.5 KB = 7.6 MB
i.e 7.6*4 approx....

Also do you know weather the size of memory required by the running program depends on RAM or HDD?

Please reply and Thank you in advance..........

johnsfine 07-16-2010 08:40 PM

Do you have a complete program that demonstrates the problem?

32MB seems pretty trivial for a modern desktop or laptop computer, so if you are running this on an rdinary computer I wouldn't jump to the conclusion it ran out of memory, and I wouldn't even ask about what (RAM, HDD, kernel parameters, etc.) might limit memory.

More likely it is some other bug in the code.

If you are running this on some very limited embedded system or an obsolete computer, then you might consider memory limits.

Edit: I looked at your other thread
http://www.linuxquestions.org/questi...9/#post4032448

There the problem clearly is that you ran out of memory, because you tried to allocate an impossibly large amount. But now you're asking about a seg fault. Your post implies you think it is still a memory capacity problem, but the difference in results (seg fault vs. bad alloc) should tell you that you are looking at a different kind of problem.

TheIndependentAquarius 07-16-2010 11:09 PM

Mayank,

Do you realize that this forum is for introductions only !!

This is your second technical thread here. I had reported your previous thread to moved to the Programming forum.
I am reporting this one too.

Kindly take care next time while posting your questions. In the below link you can choose the various forums according to your need.
http://www.linuxquestions.org/questions/

EDIT
Read the THIS link too and put your code in [CODE] tags

mayankladoia 07-17-2010 02:19 AM

Hi John,
Thanks a lot for your reply.... yes u r right it is not because of vectors the erroro is in nested for loop x*x*x = 2000*2000*2000
following is the code which i am running on x[2000][2000] array:

for(i=0;i<x;i++)
{
for(j=0;j<x;j++)
{
inf>>arr[i][j];
if(arr[i][j]==0)
{
ind[i][j]=0;
}
else
{
ind[i][j]=1;
}
}
}

after running this code arr[][] contains only 0 in all cells ie arr[][]= 0 is
0 0 0 0 0 0 0 0 ............ 2000 times
0 . . . ....................
0 . . . ....................
0 .........................
0 ........................
.
.
.
2000 times

This only happens if size of x is 2000 for x=1000 same code is running fine.

Can you suggest solution for the same.....

unSpawn 07-17-2010 03:11 AM

Moved: This thread is more suitable in the Programming Forum and has been moved accordingly to help your thread/question get the exposure it deserves.


All times are GMT -5. The time now is 12:46 AM.