LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 09-26-2008, 08:44 AM   #16
ErV
Senior Member
 
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 62

paulsm4, fantas
Thanks for the info. If ODE documentation was incorrect, fine (I haven't tested on linux simulations which required 70mb stack). But that's strange why OP get segfault and not stack overflow or compiler warnings.

Anyway, OP's program crashes during entry of main function. So it looks like it's stack problem after all.
Possible solutions:
1) Use "new" or "malloc" to allocate arrays, maybe together with simple wrapper class that will automatically destroy array when it isn't needed anymore.

2) Allocate array outside of function (so it'll be global variable):
Code:
#include<iostream>

using namespace std;

const int xSize=1024, ySize=768, depth=3;
int graphic[ySize][xSize][depth];

int main(int argc, char *argv[]){
	int test=0;

	for(int i=0;i<ySize;i++){
		for(int j=0;j<xSize;j++){
			graphic[i][j][0]=i;
			graphic[i][j][1]=j;
			graphic[i][j][2]=i+j;
		}
	}

	return test;
}
3) Make array static:
Code:
#include<iostream>

using namespace std;

int main(int argc, char *argv[]){
	int test=0;

	const int xSize=1024, ySize=768, depth=3;
	static int graphic[ySize][xSize][depth];

	for(int i=0;i<ySize;i++){
		for(int j=0;j<xSize;j++){
			graphic[i][j][0]=i;
			graphic[i][j][1]=j;
			graphic[i][j][2]=i+j;
		}
	}

	return test;
}
All three will work.

Last edited by ErV; 09-26-2008 at 08:50 AM.
 
Old 09-26-2008, 01:51 PM   #17
fantas
Member
 
Registered: Jun 2007
Location: Bavaria
Distribution: slackware, xubuntu
Posts: 143

Rep: Reputation: 22
Quote:
Originally Posted by ErV View Post
paulsm4, fantas
Thanks for the info. If ODE documentation was incorrect, fine (I haven't tested on linux simulations which required 70mb stack). But that's strange why OP get segfault and not stack overflow or compiler warnings.
There must be tons of infos about this around, I for one just had a look into the details about setrlimit in the linux man pages and was already lucky. It says:

Quote:
Originally Posted by http://linux.die.net/man/2/setrlimit
RLIMIT_STACK
The maximum size of the process stack, in bytes. Upon reaching this limit, a SIGSEGV signal is generated. To handle this signal, a process must employ an alternate signal stack (sigaltstack(2)).
So there we have it
 
  


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
segmentation fault meghakolombkar Programming 0 05-04-2006 01:20 AM
What is a segmentation fault? 144419855310001 Fedora 1 04-28-2006 08:39 AM
segmentation fault! sharath patil Debian 5 04-22-2006 05:57 AM
Segmentation fault cmplet-noobie Programming 3 04-03-2006 03:52 AM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika Suse/Novell 2 12-02-2005 10:34 AM


All times are GMT -5. The time now is 01:47 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration