What is activation record in the context of C and C++?

前端 未结 4 1488
无人及你
无人及你 2020-12-02 14:33

What does it mean and how important to know about it for a C/C++ programmers?

Is it the same across the platforms, at least conceptually?

I understand it as

4条回答
  •  天涯浪人
    2020-12-02 14:56

    When we call function, we need someplace to store callers and callees' context, this place is called activation record(AKA stack frame).

    Yes, activation records compose call stack, however, that doesn't mean activation records must be stack-based. It is implementation specific.

    You may wonder "Any examples?".

    • Of course, just take a look at IBM mainframes' stackless design, the stack is not available, its activation record is heap-based.
    • Opposite, there is also the platform which doesn't provide heap(AKA heap-less), e.g., Arduino(but it also means new keyword and new-expression cannot be used).
    • Apart from hardware limitation, some functional languages cannot store local variables on stack, so their activation records are allocated on heap, if you wonder the reason, here is a good reference.

    Just like @FrakHB said, not only heap and stack, other regions of memory could also be activation record, that's what implementation specific means.

提交回复
热议问题