Use the Rational Purify API in native-code (unmanaged) programs to set and test memory state, and search for memory leaks and handles in use.
You can call Purify error and coverage monitoring API functions directly from the Purify user interface, from your program, or from the QuickWatch dialog box in Visual Studio's debugger. For example, by default Purify reports memory leaks only when you exit a program. However, if you call the Purify API function PurifyNewLeaks at key points throughout your program, Purify reports any new memory leaks it has detected since the last time the function was called. This periodic checking enables you to track memory leaks closely and find elusive leaks.
To call Purify API functions interactively from the Purify user interface:
You can call most Purify memory API functions and handle API functions by selecting them in the Purify View menu while your program is running. You can call the PurifyNewLeaks function by clicking .
To call Purify API functions from your Visual C++ program:
1. Add #include "pure.h" to any source file in which you want to use API functions.
2. Add pure_api.c, located in the Purify product directory, to the list of source files in the project.
3. In Visual Studio, select Tools > Options.
4. Depending on your Visual Studio version, in either the Project Solutions->VC++ Directories or in the Directories tab, add Purify's product directory to the list of directories for include files.
5. Call the API functions in your code as appropriate.
If you're working from the command line, all you need to do is add #include "pure.h" to your source file before calling the API functions. Then, assuming Purify is installed in C:\Program Files\IBM\RationalPurifyPlus, type:
cl /I"C:\Program Files\IBM\RationalPurifyPlus" test.cpp "C:\Program Files\IBM\RationalPurifyPlus\pure_api.c"
To call Purify API functions interactively from the QuickWatch dialog box:
1. Add pure_api.c, located in the Purify product directory, to the list of source files in the project.
2. Build your program.
3. Instrument your program.
4. Run your program in the debugger as usual. To call an API function, select Debug > QuickWatch.
5. Type the expression you want to evaluate in the QuickWatch dialog box; for example, PurifyNewLeaks().
6. Click Recalculate in the QuickWatch dialog box.
Notes:
§ In order for Purify to intercept these API functions, you must build your program with relocation data. In Visual Studio, you can build a release or debug version of your program that contains relocation data by specifying the /fixed:no and /incremental:no linker options. For more information on the recommended settings for Visual Studio, click or for Visual Studio 6, click
.
§ The Purify error and coverage monitoring API functions are disabled in the View menu for memory profiling runs.
(C) Copyright IBM Corporation 1992, 2010.