_CRTDBG_CHECK_ALWAYS_DF导致高CPU

  这几天遇到了一个问题,很头疼。以前的一个程序,修改了部分功能后在测试中突然发现cpu很高,用鼠标操作界面也变得顿和卡了。想了各种办法都没有找到原因,今天把

_CrtSetDbgFlag的参数去掉了_CRTDBG_CHECK_ALWAYS_DF,一下子问题就解决了。
看了msdn的文档,这个标志导致频繁调用_CrtCheckMemory,导致cpu很高。msdn的文档是在这么解释的:
The behavior of _CrtCheckMemory can be controlled by setting the bit fields of the _crtDbgFlag flag using the _CrtSetDbgFlag function. Turning the _CRTDBG_CHECK_ALWAYS_DF bit field ON results in _CrtCheckMemory being called every time a memory allocation operation is requested. Although this method slows down execution, it is useful for catching errors quickly. Turning the _CRTDBG_ALLOC_MEM_DF bit field OFF causes _CrtCheckMemory to not verify the heap and immediately return TRUE.
虽然cpu很高,但是也值得,能及时检测出很多内存错误来。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值