When do you worry about stack size?

前端 未结 19 1224
难免孤独
难免孤独 2020-12-10 12:41

When you are programming in a language that allows you to use automatic allocation for very large objects, when and how do you worry about stack size? Are there any rules o

19条回答
  •  生来不讨喜
    2020-12-10 13:47

    When do you worry about stack size?

    Never.

    If you have stack size problems it means you're doing something else wrong and should fix that instead of worrying about stack size.
    For instace:

    • Allocating unreasonably large structures on the stack - don't do it. allocate on the heap.
    • Having a ridiculously long recursion. I mean in the order of painting an image and iterating over the pixels using recursion. - find a better way to do it.

提交回复
热议问题