Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-16-2010, 06:20 PM   #1
LQ Newbie
Registered: Jul 2010
Posts: 5

Rep: Reputation: 0
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));

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..........
Old 07-16-2010, 07:40 PM   #2
LQ Guru
Registered: Dec 2007
Distribution: Centos
Posts: 5,273

Rep: Reputation: 1164Reputation: 1164Reputation: 1164Reputation: 1164Reputation: 1164Reputation: 1164Reputation: 1164Reputation: 1164Reputation: 1164
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

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.

Last edited by johnsfine; 07-16-2010 at 07:47 PM.
Old 07-16-2010, 10:09 PM   #3
Senior Member
Registered: Dec 2008
Posts: 4,667
Blog Entries: 29

Rep: Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916

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.

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

Last edited by TheIndependentAquarius; 07-16-2010 at 10:57 PM. Reason: Link modified
Old 07-17-2010, 01:19 AM   #4
LQ Newbie
Registered: Jul 2010
Posts: 5

Original Poster
Rep: Reputation: 0
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:


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.....

Last edited by mayankladoia; 07-17-2010 at 09:13 AM.
Old 07-17-2010, 02:11 AM   #5
Registered: May 2001
Posts: 28,826
Blog Entries: 55

Rep: Reputation: 3341Reputation: 3341Reputation: 3341Reputation: 3341Reputation: 3341Reputation: 3341Reputation: 3341Reputation: 3341Reputation: 3341Reputation: 3341Reputation: 3341
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Segmentation Fault (core dumped) doing su - Blinker_Fluid Solaris / OpenSolaris 5 10-07-2008 06:04 PM
Segmentation fault (core dumped) nasim751 Programming 2 01-28-2008 02:56 PM
Segmentation Fault (core dumped) newuser455 Linux - Software 3 08-28-2004 02:39 PM
Segmentation fault (core dumped) plisken Linux - General 8 09-17-2003 03:32 AM
Segmentation fault (core dumped) hasanaydin Linux - General 0 03-27-2002 07:47 AM

All times are GMT -5. The time now is 03:32 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration