Chapter 15 -- The Debug C Run-Time Library

[Previous] [Next]

Chapter 15

I've written a magazine column on debugging for several years, and I get many, many questions about memory corruption and memory leaks. If developers would just stop using memory in their programs, they wouldn't have so many problems. Right. And if we'd all stop breathing, we'd never have any trouble with our lungs. Memory is the elixir of life for your C and C++ programs, and if you want to do more about memory corruption and memory leaks than just wish they would go away, you need to be proactive about handling them. The first step you need to take is to learn how to use the Microsoft debug C run-time library.

Microsoft Visual Basic programs have an easy life because Visual Basic doesn't require you to allocate memory directly, so you don't have to worry as much about memory problems. Java advocates have been smug in telling us that in Java you never need to worry about memory because the vaunted Java Virtual Machine garbage collector will handle all your memory woes. Of course, I find it quite amusing that the bestselling tools for Java programmers are memory trackers and performance monitors that tell you how much slower your application runs because of the garbage collector.

Developers working in C and C++ get to have all the fun of wrangling memory. C and C++ offer all sorts of programming freedom, but they also provide the opportunity to do much more than just shoot yourself in the foot; you can blow off your whole leg when you make even a small mistake. Fortunately, the C run-time (CRT) library developers heard our cries of anguish and, starting with Microsoft Visual C++ 4, have built in a wonderful feature: the debug CRT (DCRT) library.

Oddly enough, many C and C++ developers don't seem to realize that the DCRT library exists. The reason the library is something of a mystery is that by default much of it is turned off. Once you get the proper flags switched on, however, you'll find out what you've been missing. In this chapter, I'll introduce the DCRT library and build two extensions, MemDumperValidator and MemStress, that will provide you with even more functionality while you're using the library.



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