Applications that are compiled in debug mode with Visual C++ .NET or with Visual C++ 2005 run very slowly (833608)
The information in this article applies to:
- Microsoft Visual C++ 2005 Express Edition
- Microsoft Visual C++ .NET (2003)
- Microsoft Visual C++ .NET (2002)
SYMPTOMSYou can port an application from Microsoft Visual C++ 6.0 or
earlier to Microsoft Visual C++ .NET or to Microsoft Visual C++ 2005, and then compile the application in debug
mode. When you run the newly compiled application, you may notice that the application
runs very slowly compared to how the application runs when you compile it in Visual C++ 6.0 and
earlier. The application runs very slowly, particularly if the
application makes many calls to allocate memory and to deallocate memory.
CAUSEThe problem occurs because a change was made to the debug C Run-Time (CRT) heap management. In Visual C++ 6.0 and
earlier, the _crtDbgFlag flag was initialized to 0x00000001 or _CRTDBG_ALLOC_MEM_DF. The CRTDBG_ALLOC_MEM_DF value of the _crtDbgFlag flag turns on heap tracking for your debug build. In Visual C++
.NET or in Visual C++ 2005, the _crtDbgFlag flag is first set to 0x04000001 or to _CRTDBG_ALLOC_MEM_DF|_CRTDBG_CHECK_DEFAULT_DF.
The _CRTDBG_CHECK_DEFAULT_DF flag value is defined as _CRTDBG_CHECK_EVERY_1024_DF and tells the debug CRT memory manager to call the _CrtCheckMemory function after 1,024 calls are made to either the malloc function or the free function. The _CrtCheckMemory function walks the CRT heap and checks for memory corruption. As
more memory is allocated, this function runs slower.
WORKAROUNDTo work around this problem, set the _crtDbgFlag flag explicitly to _CRTDBG_ALLOC_MEM_DF. To do so, use the following function call at the beginning of
your application: _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF); STATUS This
behavior is by design.REFERENCESFor more information about the _CrtSetDbgFlag C Run-Time Library function and the _crtDbgFlag flag, visit the following Microsoft Web
site:
Modification Type: | Major | Last Reviewed: | 1/5/2006 |
---|
Keywords: | kbCompiler kbMigration kbDebug kbCRT kbprb KB833608 kbAudDeveloper |
---|
|