_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很高,但是也值得,能及時檢測出很多內存錯誤來。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章