I need to do it for a C++ program that needs a lot of stack. I use g++ (included in OS X Lion) to compile it. How could I increase it for my program?
3
-
You can do that with ulimit -s. – Lazylabs Apr 18 '12 at 17:08
-
I can not: sudo ulimit -s 128000 /usr/bin/ulimit: line 4: ulimit: stack size: cannot modify limit: Invalid argument – Open the way Apr 18 '12 at 17:09
-
This can help - developer.apple.com/library/mac/#qa/qa1419/_index.html – Lazylabs Apr 18 '12 at 17:15
Add a comment
|
From http://developer.apple.com/library/mac/#qa/qa1419/_index.html
Using gcc, pass link flags through to ld with -Wl:
gcc -Wl,-stack_size -Wl,1000000 foo.c
You can use getrlimit
/setrlimit
- this works on Linux, Mac OS X, and other POSIX-ish operating systems, e.g.
#include <sys/resource.h>
int main (int argc, char **argv)
{
const rlim_t kStackSize = 16 * 1024 * 1024; // min stack size = 16 MB
struct rlimit rl;
int result;
result = getrlimit(RLIMIT_STACK, &rl);
if (result == 0)
{
if (rl.rlim_cur < kStackSize)
{
rl.rlim_cur = kStackSize;
result = setrlimit(RLIMIT_STACK, &rl);
if (result != 0)
{
fprintf(stderr, "setrlimit returned result = %d\n", result);
}
}
}
// ...
return 0;
}
-
in OS X Lion, I can not set more than 32 * 1024 * 1024, but in Linux I can set even 256 * 1024 * 1024 , which is what I need. So my problem is how to surpass that limit in OS X using that code – Open the way Apr 26 '12 at 15:18
-
Well even 32 MB is a huge stack - if you really need a 256 MB stack then I think it's probably time to re-evaluate your program design. – Paul R Apr 26 '12 at 15:21
-
I agree with what you say. the problem is that the program is not mines and I have to work with it and now, it is impossible to modify it – Open the way Apr 26 '12 at 16:46
-
-
1There are some quick and easy fixes for this type of problem, e.g. if the routines with the large local variables are only used in a single thread then you can just make the largest locals
static
. – Paul R Apr 26 '12 at 17:39