reading information about how to increase stack size for a c++ application compiled with gnu, at compilation time, I understood that it can be done with setrlimit at the beginning of the program. Nevertheless I could not find any successful example on how to use it and in which part of the program apply it in order to get a 64M stack size for a c++ program, could anybody help me?
Thanlks
To get beyond the hard limit in setrlimit (on OSX its only 64MB by default), create a new thread using pthreads with a stack size of your choice. Here's a C snippet:
See if the runtime execution maximum is limiting it:
Note that the stack size, by default, is limited to 10 MiB. So to increase it to 64 MiB:
Normally you would set the stack size early on, e,g, at the start of
main()
, before calling any other functions. Typically the logic would be:getrlimit
to get current stack sizesetrlimit
to increase stack size to required sizeIn C that might be coded something like this: