How to allow more memory and avoid stack overflow on lots of recursion?

前端 未结 5 2037
-上瘾入骨i
-上瘾入骨i 2021-01-06 19:33

I\'m testing the timing of an algorithm that does lots of recursive calls. My program dies at about 128k recursive calls, and this takes only .05 seconds. I\'d like to allow

5条回答
  •  时光取名叫无心
    2021-01-06 20:06

    Take a look at setrlimit():

    RLIMIT_STACK
    This is the maximum size of the initial thread's stack, in bytes. The implementation does not automatically grow the stack beyond this limit. If this limit is exceeded, SIGSEGV shall be generated for the thread. If the thread is blocking SIGSEGV, or the process is ignoring or catching SIGSEGV and has not made arrangements to use an alternate stack, the disposition of SIGSEGV shall be set to SIG_DFL before it is generated.

提交回复
热议问题