进程的虚拟地址空间
虚拟地址空间图
- 32位系统上进程的4G的虚拟地址空间
- 3G的用户空间和1G的内核空间
- 0x00000000 ~ 0x08048000的内存时不可访问内存。
- .text段:存储代码生成的指令。
- .rodata只读数据段:常量字符串等。
- .data段:初始化不为0的全局数据,静态数据等。
- .bss段:初始化为0和不初始化全局数据。
- .heap堆区:进程刚开始是不划分的,程序第一次调用new时,才会分配堆区。
- .satck栈区:函数开辟栈帧。
分析如下代码
int gdata1 = 10; // .data
int gdata2 = 0; // .bss
int gdata3; // .bss
static int gdata4 = 11; // .data
static int gdata5 = 0; // .bss
static int gdata6; // .bss
int main() // 指令 .text
{ // 指令 .text
int a = 12; // 指令 .text
int b = 0; // 指令 .text
int c; // 指令 .text
const char* = "hello"; // .rodata
static int d = 10; // .data
static int e = 0; // .bss
static int f; // .bss
return 0; // 指令 .text
} // 指令 .text