为什么VC经常输出烫烫烫烫烫烫烫烫
luyued 发布于 2011-06-06 21:27 浏览 N 次在 Debug 模式下,
VC 会把未初始化的栈内存全部填成 0xcc,当字符串看就是 烫烫烫烫……
会把未初始化的堆内存全部填成 0xcd,当字符串看就是 屯屯屯屯……
可以让我们方便地看出那些内存没初始化
但是 Release 模式下不会有这种附加动作,原来那块内存里是什么就是什么
名字 描述
0xCD Clean Memory 申请的内存由malloc或者new完成
0xDD Dead Memory 释放后的内存,用来检测悬垂指针
0xFD Fence Memory 动态申请后的内存值,没有初始化。用来检测数组的下标界限
0xAB (Allocated Block?) 使用LocalAlloc()分配的内存 0x0DF0ADBA Bad Food 使用LocalAlloc并且参数为LMEM_FIXED,但是还没写入
0xCC 使用了/GZ选项,没有初始化的自动变量在DBGHEAP.C文件中,
Microsoft's memory management functions often initialize memory with special values. The following article describes frequent used variants.
Microsoft Visual C++ Runtime library
C runtime library provides it own debug codes:
0xCD, 0xCDCDCDCD - New objects. New objects are filled with 0xCD when they are allocated.
0xFD, 0xFDFDFDFD - No-man's land memory. Extra bytes that belong to the internal block allocated, but not the block you requested. They are placed before and after requested blocks and used for data bound checking.
0xDD, 0xDDDDDDDD - Freed blocks. The freed blocks kept unused in the debug heap's linked list when the _CRTDBG_DELAY_FREE_MEM_DF flag is set are currently filled with 0xDD. Although in some cases you won't see magic 0xDDDDDDDD value, as it will be overwritten by another debug function (e.g. 0xFEEEFEEE for HeapFree).
These constants are defined in DbgHeap.c file as
static unsigned char _bNoMansLandFill = 0xFD; /* fill no-man's land with this */
static unsigned char _bDeadLandFill = 0xDD; /* fill free objects with this */
static unsigned char _bCleanLandFill = 0xCD; /* fill new objects with this */
Compiler initialisations
0xCC, 0xCCCCCCCC - The /GX Microsoft Visual C++ compiler option initialises all local variables not explicitly initialised by the program. It fills all memory used by these variables with 0xCC, 0xCCCCCCCC.
Windows NT memory codes
0xABABABAB - Memory following a block allocated by LocalAlloc().
0xBAADF00D - "Bad Food". This is memory allocated via LocalAlloc( LMEM_FIXED, ... ). It is memory that has been allocated but not yet written to.
0xFEEEFEEE - OS fill heap memory, which was marked for usage, but wasn't allocated by HeapAlloc() or LocalAlloc(). Or that memory just has been freed by HeapFree().
- 06-30· 引用 (原创)陌上花.赏菊
- 06-21· “感动南京”人物谢二喜
- 06-21· 男士服饰搭配的基本原则
- 06-21· 程式内衣简介
- 06-21· 搭配点评 无论你身材、肤
- 06-21· 品牌内衣
- 06-21· 红脸蛋与绿西瓜
- 06-19· [神马]【2011-03-03】外贸童
- 06-19· 济南小商品 济南大明湖东
- 06-19· 妒
- 06-19· 2011年03月24日
- 06-19· 一个小小的纹身
- 06-19· 女装,女鞋,超值店
- 06-19· 谈谈购房体会
- 06-19· [转载]中医肾病用药体会
- 06-19· 我的读书心得体会
- 06-19· [转载]学习精细化管理写了
- 06-19· 谈谈拜《楞严经》的体会
- 06-18· 上海基本药物增补高价外
- 06-18· 辉瑞与百时美施贵宝叫停