reference:
Table of Contents
Memory Layout of the C Program
When you run any C program, its executable image is loaded into the RAM of the computer in an organized manner which is called the process address space or memory layout of the C program. This memory layout is organized in the following fashion:
- Text or Code Segment
- Initialized Data Segments
- Uninitialized Data Segments(BSS)
- Stack Segment
- Heap Segment
- Unmapped or Reserved Segments
Text or Code Segment
The code segment, also known as the text segment which contains the machine code of the compiled program. The text segment of an executable object file is often a read-only segment that prevents a program from accidently modified. So this memory contains .bin
or .exe
or .hex
etc.
As a memory region, a text segment may be placed below the heap or stack in order to prevent heaps and stack overflows from overwriting it.
Data Segments
The data segment stores program data. This data could be in the form of initialized or uninitialized variables, and it could be local or global. The data segment is further divied into four sub-data segments(initialized data segment, uninitialized or .bss data segment, stack and heap) to store variables depending upon if they are local or global, and initialzed or uninitialized.
Initialized Data Segment
Initialized data or simply data segment stores all global, static, constant and external variables(declared with extern keyword) that are initialized beforehand.
Note that, that data segment is not read-only, since the values of the variables can be changed at run time.
This segment can be further classified into the initialized read-only area and the initialized read-write
area.
All global, static and external variables are stored in initialized read-write memory except the const variable.
// This will be stored in initialized read-only memory
const int i = 100;
// This will be stored in initialized read-write memory
int j = 1;
char c[12] = "EmbeTronicX"
int main()
{
}
Uninitialized Data Segment
The uninitialized data segment is also called as BSS segment. BSS stands for Block Started by Symbol named after an ancient assembler operator. The uninitialized data segment contains all global and static variables that are initialzed to zero or do not have explicit initialization in the source code.
// This will be stored in uninitialized read-only memory
static int i = 0;
int j;
int main()
{
}
标签:Layout,read,data,memory,program,Memory,initialized,segment From: https://www.cnblogs.com/archerqvq/p/18160421ATTENTION: I think the