K
Koen
Hi,
I am trying to track a segmentation fault (EXC_BAD_ACCESS) that's
happening in a program I use on Mac OS X (not my own code). The reason
for the fault is that the default stack on Mac OS X is small. If I
call 'unlimit stack' before I start the program, there is no error.
However, I would like to avoid typing ulimit stack every time.
Examining the code indicates that 2 large static arrays are defined
outside main() as well as many array's inside main():
static int myarray[20][10000];
static int anotherarray[20][10000];
int main (int argc, char **argv)
{
int labels[20];
int names[20][10000];
float num[20][10000];
.....
So, after some reading, I understand I can add something like this to
the code, to increase the stack:
struct rlimit rlim;
getrlimit(RLIMIT_STACK, &rlim);
rlim.rlim_cur = RLIM_INFINITY;
setrlimit(RLIMIT_STACK, &rlim);
Unfortunately, even if I put this right after int main (int argc, char
**argv), I still get the error. If I use gdb, I immediately drop in
the error after main() starts. So I suspect the compiler is creating
all the array's first, using all the available stack.
Is there a way to modify the code so that the 'rlimit' snippit is
called before everything else happens? Or maybe I need to use
different compiler settings?
thanks,
- Koen.
I am trying to track a segmentation fault (EXC_BAD_ACCESS) that's
happening in a program I use on Mac OS X (not my own code). The reason
for the fault is that the default stack on Mac OS X is small. If I
call 'unlimit stack' before I start the program, there is no error.
However, I would like to avoid typing ulimit stack every time.
Examining the code indicates that 2 large static arrays are defined
outside main() as well as many array's inside main():
static int myarray[20][10000];
static int anotherarray[20][10000];
int main (int argc, char **argv)
{
int labels[20];
int names[20][10000];
float num[20][10000];
.....
So, after some reading, I understand I can add something like this to
the code, to increase the stack:
struct rlimit rlim;
getrlimit(RLIMIT_STACK, &rlim);
rlim.rlim_cur = RLIM_INFINITY;
setrlimit(RLIMIT_STACK, &rlim);
Unfortunately, even if I put this right after int main (int argc, char
**argv), I still get the error. If I use gdb, I immediately drop in
the error after main() starts. So I suspect the compiler is creating
all the array's first, using all the available stack.
Is there a way to modify the code so that the 'rlimit' snippit is
called before everything else happens? Or maybe I need to use
different compiler settings?
thanks,
- Koen.