memory management is one of the most important topics for a Programmer, and so understanding the Memory Layout of a C Program and Memory Layout of a Process becomes essential.
For high-level languages such as Java, Python, C#, Memory is partially managed by the language itself as it has a Garbage Collector, which deallocates and frees the allocated memory while not in use. But there is no such garbage collector in C & C++, and so the programmer must manually release the allocated memory.
The C program is first compiled and translated to an executable object file. When the executable is run, it takes the main memory area, i.e. the RAM, and the CPU runs the executable instructions.
If you are not aware of the processes involved in compiling the C program from source to binary, read C Program Compilation Process.
The Typical Memory Layout of a C Program consists of the following segments:
- Command Line Arguments
- Stack
- Heap
- Uninitialized Data Segment (BSS)
- Initialized Data Segment (data)
- Text/Code Segment (text)
text段和data段中, 有时候也会划分出一个rodata段, 以区分执行的代码逻辑和固定字符串固定值等;
The above layout segments can be broadly classified into two:
- Static Memory Layout – Text/Code, Data Segments
- Dynamic Memory Layout – Stack & Heap
The C Program executable already contains some of the segments, and some are built dynamically at runtime.
摘录文章
- Memory Layout Of A C Program
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)