LinuxQuestions.org
Visit Jeremy's Blog.
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
  Search this Thread
Old 05-31-2011, 12:11 PM   #1
nushki
LQ Newbie
 
Registered: Mar 2009
Posts: 26

Rep: Reputation: 0
multiple arrays


Hi all,

im stuck again with something simple. there is a 4-dimensional array, but it gives segmentation fault when one of dimensions is big like 30000. dont know why :"(



#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>


#define N_I 30000


int main (int argc, char* argv[])
{
printf("!!!!1 \n");
int m[18][30][N_I][4];
int i,j,k,l;
for (i=0;i<18;i++)
for (j=0;j<30;j++)
for (k=0;k<N_I;k++)
for (l=0;l<4;l++)
{
m[i][j][k][l]=i+j+k+l;
printf("%d\n",m[i][j][k][l]);
}

return 0;
}


it works fine when N_I=300; but crashes when N_I=30000;



thank you
 
Old 05-31-2011, 12:21 PM   #2
nushki
LQ Newbie
 
Registered: Mar 2009
Posts: 26

Original Poster
Rep: Reputation: 0
ups, i think i got it, i run in on cluster and since big arrays take a lot of space may be it was not allowed to take it, but when i run it on my laptop it works.


sorry
 
Old 05-31-2011, 12:27 PM   #3
Nathan.eth0
LQ Newbie
 
Registered: Apr 2011
Posts: 21

Rep: Reputation: 2
You cant use that many loops. Your program crashes. Depending on how much your RAM capacity is, there are limitations.
Once I was trying to create a word combination list, I used multiple for loops but my core got dumped.
Its way more complex than you could understand.

Last edited by Nathan.eth0; 05-31-2011 at 12:30 PM.
 
1 members found this post helpful.
Old 05-31-2011, 12:44 PM   #4
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by nushki View Post
ups, i think i got it, i run in on cluster and since big arrays take a lot of space may be it was not allowed to take it, but when i run it on my laptop it works.


sorry
If you wish, try increasing the size of your stack, using the following command:
Code:
ulimit -s unlimited
Then re-run your program.... but seriously, why would you want to? Do you really want the program looping so many times?

Next time, if you require a large array (single or multi-dimensional), allocate it on the heap rather than declare it on the stack.
 
1 members found this post helpful.
Old 05-31-2011, 12:51 PM   #5
nushki
LQ Newbie
 
Registered: Mar 2009
Posts: 26

Original Poster
Rep: Reputation: 0
thank you!!!
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Arrays of Structures to Arrays of Classes knobby67 Programming 1 01-01-2008 01:39 PM
multiple md raid arrays edgjerp Linux - Software 0 10-13-2007 07:28 AM
Multiple Autologins; Multiple Users; Multiple Sessions mrclisdue Linux - Desktop 1 09-26-2007 05:50 AM
Question about multiple type arrays RavenLX Programming 2 02-27-2007 11:10 AM
Question about outputing arrays with pointers, then just arrays... RHLinuxGUY Programming 1 04-12-2006 05:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:11 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration