CS2604 Programming Tools




Memwatch

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.