How to increase stack size for a ruby app. Recursive app getting: Stack level too deep (SystemStackError)

前端 未结 7 1839
感情败类
感情败类 2020-11-30 02:53

Posting a stack overflow question on stackoverflow.com, how amusing :-)

I\'m running some recursive Ruby code and I get the: \"Stack level too deep (SystemStac

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 03:45

    Think about what is going on with the code. As other posters have mentioned it is possible to hack the C code of the interpreter. However. the result will be that you are using more RAM and have no guarantee that you won't blow the stack again.

    The really good solution would be to come up with an iterative algorithm for what you are trying to do. Sometimes memoisation can help and sometimes you find you are not using the stuff you are pushing on the stack in which case you can replace recursive calls with mutable state.

    If you are new to this sort of stuff have a look at SICP here for some ideas...

提交回复
热议问题