#ifndef MEMCHECK_H #define MEMCHECK_H ///////////////////////////////////////////////////////////////////// // memCheck.h - utility to check heap memory allocations // // ver 1.0 // // // // Language: Visual C++, ver 6.0 // // Platform: Dell XPs1000r, Windows 2000 Professional // // Application: ImageTrek Project - CASE Center // // Author: Jim Fawcett, CST 2-187, Syracuse Univ. // // jfawcett@twcny.rr.com, (315) 443-3948 // ///////////////////////////////////////////////////////////////////// /* Class Operations: ================= The memCheck class provides heap checking operations. You can show the current state of the heap, or show the difference between two states. This class is a thin wrapper around the _Crtxxx functions provided by the Win32 API. Public Interface: ================= memCheck mc; // construct a memCheck object memCheck mc("a name"); // construct an object with name memCheck mc(CrtMemState); // construct object from _CrtMemState mc.name("new name"); // give existing object a new name char *name = mc.name(); // retrieve name mc.refresh(); // refresh the heap state information _CrtMemState ms = mc; // cast to a Win32 _CrtMemState struct if(mc1 == mc2) // do something // test to see if state has changed mc.state(); // display the heap state mc1.stateDiff(mc2); // display difference in state memCheck::stateDiff(mc1,mc2); // display difference in state */ ///////////////////////////////////////////////////////////////////// // build process // ///////////////////////////////////////////////////////////////////// // Required files: // // memCheck.h, memCheck.cpp // // // // Command line compile: // // cl /GX /DTEST_MEMCHECK memCheck.cpp // ///////////////////////////////////////////////////////////////////// /* Maintenance History: ==================== ver 1.0 : 11 Mar 2001 - first release */ // #include #define MAX 80 class memCheck { friend void stateDiff(const memCheck &, const memCheck &); public: memCheck(const char *s = NULL); memCheck(const _CrtMemState &ms); ~memCheck(); void name(const char *s); const char* name() const; void refresh(); operator _CrtMemState (); void state(); void stateDiff(const memCheck &d); bool operator==(const memCheck &d); bool isCorrupt(); private: _CrtMemState memState; char objName[MAX+1]; static const char* makeTitle(const char *name1, const char *name2); }; inline memCheck::operator _CrtMemState () { return memState; } #pragma warning(disable : 4800) // conversion performance warning inline bool memCheck::isCorrupt() { return _CrtCheckMemory(); } void stateDiff(const memCheck &d1, const memCheck &d2); #endif