为什么VC经常输出烫烫烫烫烫烫烫烫(内存在不同状态下默认填充的字符)

在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 memorymanagement 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 areallocated.
0xFD, 0xFDFDFDFD - No-man's land memory. Extra bytes that belong to the internal block allocated, but not the block you requested. They are placedbefore and after requested blocks and used for data bound checking.
0xDD, 0xDDDDDDDD - Freed blocks. The freed blocks kept unused in the debugheap's linked list when the _CRTDBG_DELAY_FREE_MEM_DF flag is set are currentlyfilled 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 forHeapFree).

These constants are defined in DbgHeap.c file as:
1. static unsigned char _bNoMansLandFill = 0xFD; /* fill no-man's land with this*/
2. static unsigned char _bDeadLandFill = 0xDD; /* fill free objects with this */
3. static unsigned char _bCleanLandFill = 0xCD; /* fill new objects with this */

Compiler initialisations
0xCC, 0xCCCCCCCC - The /GX Microsoft Visual C++ compiler option initialises alllocal variables not explicitly initialised by the program. It fills all memoryused 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'tallocated by HeapAlloc() or LocalAlloc(). Or that memory just has been freed byHeapFree().


Original URL: http://hi.baidu.com/dbfr2011818/item/b153d2f6c6c40ccd521c2633

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值