Features of the Debug C Run-Time Library

[Previous] [Next]

The main claim to fame for the DCRT library is its wonderful heap memory tracking support. All the memory allocated through standard C/C++ memory allocation functions, such as new, malloc, and calloc, can be tracked in debug builds. The tracking checks for memory underwrites, in which your program writes past the beginning of a block of memory, and memory overwrites, in which your program writes past the end of a block of memory. The tracking also monitors and reports memory leaks in your application. If you've been writing Microsoft Foundation Class (MFC) library programs, you've probably noticed the memory leak reports when your application ends; those leak reports come from the DCRT library. MFC partially turns on the DCRT library for you automatically.

Another neat feature of the DCRT library is the reporting subsystem, which you and I would call trace, through its _RPTn and RPTFn macros and assertion support. I introduced the DCRT library assertion support in Chapter 3 and explained some of the issues associated with using it. As I mentioned, the DCRT library assertions are good, but they destroy the last error value and therefore cause debug and release builds to behave differently. For your assertions, I strongly recommend that you use the SUPERASSERT assertion code that's part of BUGSLAYERUTIL.DLL.

Another nice feature of the DCRT library is that its source code is included with the compiler. Table 15-1 lists all the files that make up the DCRT library. If you elected to install the CRT library source code when you installed Microsoft Visual Studio, which I highly recommend doing, you can find all the CRT and DCRT library source code in the <VC Directory>\CRT\SRC directory.

Table 15-1 Debug C Run-Time Library Source Files

Source FileDescription
DBGDEL.CPPThe debug global delete operator.
DBGHEAP.CAll the debug heap-handling functions.
DBGHOOK.CThe stub memory allocation hook function.
DBGINT.HThe internal debug headers and functions.
DBGNEW.CPPThe debug global new operator.
DBGRPT.CThe debug reporting functions.
CRTDBG.HThe header file you include. This file is in the standard include directory.



Debugging Applications
Debugging Applications for MicrosoftВ® .NET and Microsoft WindowsВ® (Pro-Developer)
ISBN: 0735615365
EAN: 2147483647
Year: 2000
Pages: 122
Authors: John Robbins

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net