Aug 6, 2009

Customizing process stack size in Mac machine

Each Mac OS X process is launched with a default stack size of 8 Megabytes. This allocation is used exclusively for the main thread's stack needs. Each subsequent thread created is allocated its own default stack, the size of which differs depending on the threading API used. For example, the Mac OS X implementation of Pthreads defines a default stack size of 512 Kilobytes, while Carbon MPTasks are created with a 4 Kilobyte stack.

Since certain system defaults and limits can change between releases of Mac OS X, it is useful to be able to determine the default process stack size for the system you are developing on. From the command line, limit (csh, tcsh) or ulimit -a (sh, bash) will output a variety of system defaults including the default process stack size.

If you find your application is crashing because it is outgrowing the default 8 Megabyte stack allocation, you can raise its default by passing the -stack_size flag on the link line and specifying a new stack size up to 64 Megabytes.

Setting a Larger Stack at Link Time:

Using gcc, pass link flags through to ld with -Wl:

gcc -Wl,-stack_size -Wl,1000000 foo.c

For details follow the link

No comments: