88 2. Tools of the Trade
portant data that was there—while simultaneously failing to update the mem-
ory location where that data should have been writt en. Blame for both of these
problems falls squarely on the language feature known as the pointer.
A pointer is a powerful tool. It can be an agent of good when used prop-
erly—but it can also be all-too-easily transformed into an agent of evil. If a
pointer points to memory that has been freed, or if it is accidentally assigned
a nonzero integer or fl oating-point value, it becomes a dangerous tool for cor-
rupting memory, because data writt en through it can quite literally end up
anywhere. Likewise, when pointers are used to keep track of allocated mem-
ory, it is all too easy to forget to free the memory when it is no longer needed.
This leads to memory leaks.
Clearly good coding practices are one approach to avoiding pointer-re-
lated memory problems. And it is certainly possible to write solid code that
essentially never corrupts or leaks memory. Nonetheless, having a tool to help
you detect potential memory corruption and leak problems certainly can’t
hurt. Thankfully, many such tools exist.
My personal favorite is IBM’s Rational Purify, which comes as part of the
Purify Plus tool kit. Purify instruments your code prior to running it, in order
to hook into all pointer dereferences and all memory allocations and dealloca-
tions made by your code. When you run your code under Purify, you get a
live report of the problems—real and potential—encountered by your code.
And when the program exits, you get a detailed memory leak report. Each
problem is linked directly to the source code that caused the problem, making
tracking down and fi xing these kinds of problems relatively easy. You can fi nd
more information on Purify at htt p://www-306.ibm.com/soft ware/awdtools
/purify.
Another popular tool is Bounds Checker by CompuWare. It is similar
to Purify in purpose and functionality. You can fi nd more information on
Bounds Checker at htt p://www.compuware.com/products/devpartner/visualc
.htm.
2.5 Other Tools
There are a number of other commonly used tools in a game programmer’s
toolkit. We won’t cover them in any depth here, but the following list will
make you aware of their existence and point you in the right direction if you
want to learn more.
z Diff erence tools. A diff erence tool, or diff tool, is a program that com-
pares two versions of a text fi le and determines what has changed be-