About C/C++ stack allocation

前端 未结 7 697
一个人的身影
一个人的身影 2020-12-15 12:44

While studying C++ (and C) I had some particular doubts regarding the working of stack allocation, that I can\'t find a solution to:

  1. Does stack allocation c

7条回答
  •  长情又很酷
    2020-12-15 13:27

    Stack allocation is typically done in terms of alloca() or implicitly by the compiler. A well-done alloca() will only require a scant few instructions, and there is no cost (or even a need) to free it when you're done.

    You can pass a pointer to memory allocated by alloca() to any other function/method that expects a pointer. You MUST NEVER return a pointer allocated by alloca().

    Here are some advantages and disadvantages to using stack allocation.

提交回复
热议问题