Why are stack overflows still a problem?

前端 未结 11 1456
故里飘歌
故里飘歌 2020-12-25 10:22

This question is mystifying me for years and considering this site\'s name, this is the place to ask.

Why do we, programmers, still have this StackOverflow

11条回答
  •  失恋的感觉
    2020-12-25 10:57

    Having practically infinite stack space would be very bad in the case of a infinite recursion because it would turn an easily diagnosed error (stack overflow) into a much more problematic error (out of memory). With a stack overflow, a look at the stack trace will fairly quickly tell you what is going on. Alternately, when the system is out of memory, it may attempt other methods of solving it, such as using swap space, resulting in serious performance degradation.

    On the other hand, I have rarely had issues with hitting the stack overflow barrier due to recursion. However, I can think of a couple of circumstance where it happened. However, moving to my own stack implemented as a std::vector was a simple solution to the problem.

    Now, what would be neat is if the language would allow me to mark a particular function as "heavily recursive", and then have it operate in its own stack space. That way I'd generally get the advantage of stopping when my recursion is out of whack, but I could still make use of extensive recursion when I wanted to.

提交回复
热议问题