linux和windows内存布局验证

来源:互联网 发布:android性能优化工具 编辑:程序博客网 时间:2024/06/16 01:12
#if 1
//内存布局的验证
#include <stdio.h>
int globle_init = 0;
int globle_uinit;
static int globle_static = 0;


int main()
{
int local_init = 0;
static int local_static = 0;
int *local_ptr;


local_ptr = (int *)malloc(10);


printf("address of main is %p\n", main);
printf("address of globle_init is %p\n", &globle_init);
printf("address of globle_uinit is %p\n", &globle_uinit);
printf("address of globle_static is %p\n", &globle_static);
printf("address of local_init is %p\n", &local_init);
printf("address of local_static is %p\n", &local_static);
printf("address of &local_ptr is %p\n", &local_ptr);
printf("address of local_ptr is %p\n", local_ptr);
//////////////////////////////////////////////////////////////////////////
/*
//windows
address of &local_ptr is0031FB70 stack
address of local_init is0031FB7C stack
address of local_ptr is00378820 heap
address of main is00AD1145 text
address of globle_init is   00AD8130  data
address of globle_static is 00AD8134data
address of local_static is  00AD8138data
address of globle_uinit is  00AD8160data


//linux
address of local_init is0x7fff4397784c stack
address of &local_ptr is0x7fff43977840 stack
address of local_ptr is0x828010         heap
address of globle_uinit is0x601064 data
address of local_static is0x601060 data
address of globle_static is 0x60105cdata
address of globle_init is0x601058 data
address of main is0x400650 text

*/
//////////////////////////////////////////////////////////////////////////


free(local_ptr);
printf("ok\n");
return 0;


}




#endif
0 0
原创粉丝点击