C++ How to allocate memory dynamically on stack?

后端 未结 7 1050
南旧
南旧 2020-12-04 11:07

Is there a way to allocate memory on stack instead of heap? I can\'t find a good book on this, anyone here got an idea?

7条回答
  •  再見小時候
    2020-12-04 12:01

    When/if C++ allows the use of (non-static) const values for array bounds, it will be easier.

    For now, the best way I know of is via recursion. There are all kinds of clever tricks that can be done, but the easiest I know of is to have your routine declare a fixed-sized array, and fill and operate on what it has. When its done, if it needs more space to finish, it calls itself.

提交回复
热议问题