CS2604 Programming Tools


Memwatch is a small module that replaces the standard C++ operators new and delete with versions that add extra debugging features. Adding Memwatch to your program project won't cure problems, but it will add extra memory checking that will sometimes detect and report existing problems so oyu can fix them. Problems detected include:

There are three files you can download:

To use Memwatch, follow these simple steps:

Warning Regarding Free Lists!

Under Microsoft Visual C++ Memwatch.h redefines "new" to be a macro in order to work with VC++'s debugging runtime library. This means it may cause strange compiler errors or warnings if you are defining your own overloaded new/delete operators to maintain free lists for your ADTs.

If this is the case but you still want to use Memwatch, simply place "#ifdef _DEBUG ... #endif" around the lines of code in your .h and .cpp files where you define your operator new and operator delete code. This will allow Memwatch to work correctly.

By selecting the "Debug" or "Release" configuration of your project when compiling, you can control whether or not your own personal free list code is included (it will only be in the "Release" configuration with the above #ifdef). Memwatch will work under either configuration, but returns more detailed information in the "Debug" configuration.

This version of Memwatch was modified locally by Dr. Edwards to work with Microsoft Visual C++ in standard console-mode applications. If you are working with MFC GUI applications, use the MFC memory debugging settings described below.

Microsoft's MFC Memory Diagnostics

If you are using Microsoft Visual C++, you can use Microsoft's own memory debugging code build into the debugging version of its C++ runtime code. Microsoft has designed its memory aid to work with MFC applications, but it can also be used with plain old console-mode Win32 applications.

Microsoft's memory diagnostic features are described under the DEBUG_NEW macro in the MFC documentation. To use them in a regular program, do the following:

Check Microsoft's on-line books for "DEBUG_NEW" or "diagnostics" for more information on what you can do when this memory tracking support is enabled. DEBUG_NEW is primarily for spotting memory leaks, so it does not provide as much checking as Memwatch. It is a useful tool, however.


If you are working under Borland C++, note that Borland sells a commercial tool called CodeGuard that automatically instruments your code to spot a very wide array of memory errors. If you have a Borland's C++ Developer's Suite (version 5.0 or newer), it comes with CodeGuard for free. CodeGuard support can be easily enabled from the TargetExpert dialog. If you have it available, it is very helpful in detecting memory errors.


Purify is a commerical tool for detecting memory errors produced by Pure Atria Corp. Downloadable evaluation copies are available from their web site (only if you want to invest the time, of course).

Because Purify 4.0 has just been made available for Windows NT users, however, some promotional CDs have been sent out. Dr. Edwards has a copy of Purify 4.0 for Windows NT on CD that is good until 2/28/97. If you are working under Windows NT on your own machine and would like to play around with Purify, feel free to drop by his office during office hours to borrow it.

Go to the CS2604 Homepage.