When do you worry about stack size?

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

    If you're writing for a tiny little embedded platform, you worry about it all the time, but you also know exactly how big it is, and probably have some useful tools available to find the high-water mark of the stack.

    If you aren't, then don't worry until your program crashes :) Unless you are allocating seriously huge objects (many tens of KB), then it is never going to be a problem.

    Note, however, that objects on the stack are, by definition, temporary. Constructing (and possibly destructing) large objects frequently may cause you a performance problem - so if you have a large object it probably should be persistent and heap-based for reasons other than stack size.

提交回复
热议问题