C++ How to allocate memory dynamically on stack?

后端 未结 7 1041
南旧
南旧 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 11:54

    You can declare a local char[1024] or whatever number of bytes you'd like (up to a point), then take the address of the local for a pointer to this block of memory on the stack. Not exactly dynamic, but you could then wrap up this memory with your own memory manager if desired.

提交回复
热议问题