[ Go to August 1997 Table of Contents ]|
-- by Martin Heller
Software development is an inherently flawed process. Even great programmers make a few mistakes; the rest of us can count on making mistakes every time we touch the keyboard. For C and C++ programmers, dynamic memory allocation errors-memory leaks-are a constant headache. For Windows programmers, window and graphics-object resource leaks are a never-ending nuisance. And the list goes on.
Some problems show up when you try to compile your code. Others appear as soon as you exercise the code, as Windows or runtime-library error messages. But the really annoying problems hover silently in the background, waiting for a customer to find them using an "interesting" scenario.
Enter automatic checking programs. Tools like Purify (see WinLab Reviews, September 1996) and BoundsChecker can detect hundreds of kinds of runtime errors and leaks in Windows programs, whether or not you have the source code for the programs. Other tools like MemCheck and Great Circle require you to link their libraries into your code.
BoundsChecker 5.0 Visual C++ Edition
BoundsChecker is the doyen of this category on Windows. BoundsChecker 5.0 Visual C++ Edition works either alone or integrated with the Visual C++ IDE. The latter mode makes checking completely painless-toggling one toolbar button runs BoundsChecker every time you debug your program.
BoundsChecker validates Windows API calls, including recent additions. It also validates ActiveX, DirectX, OLE, COM and ODBC, as well as static, stack and heap errors, and memory and resource leaks. Most of these normal checks don't require any special compilation or linking. BoundsChecker can also instrument your code for more rigorous testing; it looks for subtle memory, pointer and leak errors, such as reading uninitialized memory, using an out-of-range array index and using a function pointer that is not a function.
BoundsChecker often finds many more errors than you're interested in seeing. You can control its error-detection level and what it does when it finds an error by using an option box before you start a testing run. During a run in which BoundsChecker pops up after finding a problem, you can debug the error, acknowledge it and continue, stop the program or suppress the error from being displayed in the future. Then, you can browse through the error and event log and track each error back to source code if it's available.
In the past, BoundsChecker used source-code insertion for its most rigorous tests, which led to extremely long compile- and runtimes. In this version, the program uses a much more efficient technique, which instruments the compiler's intermediate code.
BoundsChecker 5.0 can validate about 2,500 API and OLE functions. You can also define new API validation modules for BoundsChecker to use and, if you wish, distribute these validation modules with your programs.
BoundsChecker has saved our programming projects and reputation time after time. We can't recommend it highly enough.
Great Circle 2.1
Until recently, Great Circle was positioned as a garbage-collection utility for C and C++ programmers. It still does that, but Geodesic Systems has found that while most C programmers understand that they need to fix memory leaks (which Great Circle does), they may not understand how garbage collection can help.
Consider a C program with dynamic memory allocations-malloc calls to allocate memory, and free calls to release that memory. Normally if you malloc without a later free, the memory leaks. If you free a block twice, the memory heap becomes corrupt. Once you link it into your program, Great Circle lets you dispense with free calls. Instead, it scavenges memory in the background and periodically releases dead memory blocks-blocks for which no valid pointer is in scope. Great Circle can also report what it's doing.
Effectively, Great Circle acts as both a diagnostic and an immediate cure for memory leaks. Since it can fix memory leaks coming from third-party libraries and DLLs, as well as leaks coming from your own code, it can sometimes prove indispensable. And if you rely on Great Circle from the beginning of a project, instead of constantly trying to match your memory allocations, you can save an enormous amount of programming time.
Great Circle doesn't really compete directly with BoundsChecker-it's more of a complementary tool. It detects only a few out of the thousands of possible problems in Windows programs, while BoundsChecker detects essentially all of them. On the other hand, BoundsChecker does not actually fix anything, while Great Circle almost magically turns a program that leaks like a sieve into something solid and stable without requiring you to change a line of code.
Despite its name, MemCheck does more than check memory. It validates 500-odd API functions in addition to checking memory and resource allocation thoroughly. It also has a few functions of its own that you can call to validate memory from within your program. However, MemCheck doesn't handle ActiveX, DirectX, OLE, COM or ODBC errors.
You can add MemCheck to a project simply by linking with its library. If you want to use MemCheck's own functions, you can use its Project Configuration utility to insert source code into your C and C++ files. Suppress MemCheck calls without removing the extra source code by defining an NOMC constant.
Using MemCheck is fairly straightforward. Once you've linked your program with MemCheck's libraries, checking occurs every time you run your program. MemCheck's diagnostics quickly take you to the errant line of code and let you debug the error, continue the program or halt the program. MemCheck's error and event logs are useful after a program runs as well.
While not as thorough or convenient to use as BoundsChecker, MemCheck offers C and C++ programmers a good, solid diagnostic. MemCheck's own function calls may make it strongly desirable for finding certain kinds of problems; some people might prefer its simple design to BoundsChecker's.
Each of these tools can help make your programs more robust and reliable. BoundsChecker is our WinList pick for its thoroughness and ease of use. MemCheck is a worthwhile alternative if price is a consideration. And Great Circle can be a good quick fix for those nasty memory leaks.
Windows Magazine, August 1997, page 147.
[ Go to August 1997 Table of Contents ]