LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 07: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 07:50 AM.
 
Old 09-26-2008, 12: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 12:20 AM
What is a segmentation fault? 144419855310001 Fedora 1 04-28-2006 07:39 AM
segmentation fault! sharath patil Debian 5 04-22-2006 04:57 AM
Segmentation fault cmplet-noobie Programming 3 04-03-2006 02:52 AM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 09:34 AM

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

All times are GMT -5. The time now is 04:21 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