I found a practically code to enable debug the heap overrun:
#ifdef _DEBUG // enable CRT memory leak detection & report
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF // enable debug heap allocs & block type IDs (ie _CLIENT_BLOCK)
// | _CRTDBG_CHECK_CRT_DF // check CRT allocations too
// | _CRTDBG_DELAY_FREE_MEM_DF // keep freed blocks in list as _FREE_BLOCK type
| _CRTDBG_LEAK_CHECK_DF // do leak report at exit (_CrtDumpMemoryLeaks)
// pick only one of these heap check frequencies
// | _CRTDBG_CHECK_ALWAYS_DF // check heap on every alloc/free
| _CRTDBG_CHECK_EVERY_16_DF
// | _CRTDBG_CHECK_EVERY_128_DF
// | _CRTDBG_CHECK_EVERY_1024_DF
//| _CRTDBG_CHECK_DEFAULT_DF // by default, no heap checks
);
int mode = _CRTDBG_MODE_WNDW;
//int mode = _CRTDBG_MODE_DEBUG;
_CrtSetReportMode(_CRT_WARN, mode);
_CrtSetReportMode(_CRT_ERROR, mode);
_CrtSetReportMode(_CRT_ASSERT, mode);
// _CrtSetBreakAlloc (209) ; // break debugger on numbered allocation
// // get id number from leak detector report of previous run
#endif
No comments:
Post a Comment