What does “Memory allocated at compile time” really mean?

前端 未结 13 1073
时光取名叫无心
时光取名叫无心 2020-12-04 04:30

In programming languages like C and C++, people often refer to static and dynamic memory allocation. I understand the concept but the phrase \"All memory was allocated (rese

13条回答
  •  既然无缘
    2020-12-04 05:30

    An executable describes what space to allocate for static variables. This allocation is done by the system, when you run the executable. So your 1kB static variable won't increase the size of the executable with 1kB:

    static char[1024];
    

    Unless of course you specify an initializer:

    static char[1024] = { 1, 2, 3, 4, ... };
    

    So, in addition to 'machine language' (i.e. CPU instructions), an executable contains a description of the required memory layout.

提交回复
热议问题