LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
LinkBack Search this Thread
Old 07-16-2010, 06:20 PM   #1
mayankladoia
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));
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..........
 
Old 07-16-2010, 07:40 PM   #2
johnsfine
Senior Member
 
Registered: Dec 2007
Distribution: Centos
Posts: 4,969

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

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

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

Last edited by TheIndependentAquarius; 07-16-2010 at 10:57 PM. Reason: Link modified
 
Old 07-17-2010, 01:19 AM   #4
mayankladoia
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:

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

Last edited by mayankladoia; 07-17-2010 at 09:13 AM.
 
Old 07-17-2010, 02:11 AM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,549
Blog Entries: 51

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


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are 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 07:28 PM.

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