Linux: 进程地址空间究竟是什么?
一、内存究竟是什么?分为哪些?
在C/C++中,我们常将内存分为:代码区、常量区、全局区(静态区)、堆、栈等等。相关内存区域划分如下:(X86, 32位平台)
如何验证C/C++中各区域的相对位置呢?
我们可以在每个区域中选择一个地址来验证C/C++中各区域的相对位置!!具体如下:
【源代码】:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int un_global_val;
int Init_global_val = 100;
int main(int argc, char *argv[], char * env[])
{
printf("code addr: %p\n", main); //代码区
const char *str = "hello Linux";//字符常量区
printf("read only char add: %p\n", str);
printf("Init global value add: %p\n", &Init_global_val);//全局初始区
printf("uninit global value add: %p\n", &un_global_val);//全局未初始区
char* heap1 = (char*)malloc(100);
char* heap2 = (char*)malloc(100)