When do you worry about stack size?

前端 未结 19 1232
难免孤独
难免孤独 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:25

    I have had problems running out of stack space when:

    • A function accidentally calls itself
    • A function uses recursion to a deep level
    • A function allocates a large object on the stack, and there is a heap.
    • A function uses complicated templates and the compiler crashes

    Provided I:

    • Allocate large objects on the heap (eg. using "auto_ptr foo = new Foo" instead of "Foo foo")
    • Use recursion judiciously.

    I don't normally have any problems, so unfortunately don't know what good defaults should be.

提交回复
热议问题