关于win32 下DEBUG模式的研究

来源:互联网 发布:央视 可视化呀数据 编辑:程序博客网 时间:2024/06/02 12:37
关于win32 下DEBUG模式的研究:
参考:http://www.nobugs.org/developer/win32/debug_crt_heap.html#table
http://en.wikipedia.org/wiki/Magic_number_(programming)

http://www.cnblogs.com/pcchinadreamfly/archive/2012/04/26/2471317.html等介绍:

代码如下:

#include<iostream>#include<stdlib.h>using namespace std;int main(){    int *p=NULL;p=(int*)malloc(sizeof(int)*1);printf("%p\n",p);printf("%x\n",*(p-13));printf("%x\n",*(p-12));printf("%x\n",*(p-11));printf("%x\n",*(p-10));printf("%x\n",*(p-9));printf("%x\n",*(p-8));printf("%x\n",*(p-7));printf("%x\n",*(p-6));printf("%x\n",*(p-5));printf("%x\n",*(p-4));        printf("%x\n",*(p-3));        printf("%x\n",*(p-2));printf("%x\n",*(p-1));printf("%x\n",*(p));printf("%x\n",*(p+1));printf("%x\n",*(p+2));printf("%x\n",*(p+3));printf("%x\n",*(p+4));printf("%x\n",*(p+5));printf("%x\n",*(p+6));printf("%x\n",*(p+7));        printf("%x\n",*(p+8));        printf("%x\n",*(p+9));printf("%x\n",*(p+10));printf("%x\n",*(p+11));printf("%x\n",*(p+12));system("PAUSE");return 0;}

在这个里面我申请了一个int类型的空间,然后打印出其周围的空间中的值,其结果为:


然后将其中申请空间的语句改为:p=(int*)malloc(sizeof(int)*2),相当于是申请两个int的空间,得到的结果为:


可以看到大体的字段分布和http://www.nobugs.org/developer/win32/debug_crt_heap.html#table中最后的图是对应的,这里我只是说明几点疑惑:

1、在申请两个int空间的结果中比申请1个int空间的结果在最后的两个0上面多了一个feeefeee,而且申请偶数个空间都会出现,而申请奇数个空间都不会出现;

2、从cdcdcdcd(申请的空间未初始化)向上一直数,在http://www.nobugs.org/developer/win32/debug_crt_heap.html#table最后的图中上面是有十个字节,而在这里因为我觉得第十个字节和第九个字节没什么关系,是不是在这里是数到第九个字节;

3、如果是数到第九个字节的话,那么感觉下面要数到连续的两个0后面的那个为止,如果是第十个字节,则是数到连续的两个0为止代表本部分;这和http://www.nobugs.org/developer/win32/debug_crt_heap.html#table图的下半部分也是有区别的,因为那个文章是2009年的版本,所以现在的实现是否已经出现了变化;


0 0