home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!timbuk.cray.com!equalizer!sdcrsi!xlnt!ventura!vs@UCSD.EDU
- From: ventura!vs@UCSD.EDU (Shankar Venkataraman)
- Newsgroups: comp.lang.c++
- Subject: Re: Need Help on Debugging Objects
- Message-ID: <257@ventura.UUCP>
- Date: 8 Jan 93 01:21:07 GMT
- References: <256@ventura.UUCP>
- Sender: news@ventura.UUCP
- Reply-To: ventura!vs@UCSD.EDU
- Organization: Ventura Software, Inc., A XEROX Company
- Lines: 56
- Nntp-Posting-Host: vpdsb
-
- In article 256@ventura.UUCP, ventura!tim@UCSD.EDU (Tim Dierks) writes:
- >I am looking for ideas on how to track the creation/deletion of objects for
- >debugging purposes in an application I am writing. For the PC, The Microsoft
- >Foundation Class offers a TRACE macro that lets you display a message, but I'd like
- >more functionality, and I don't plan on use the MFC. I'd like to be able to do
- >things like those listed below:
- >
- >- Display a message each time an object is created/deleted, identifying what type of
- > object it is, and some unique identifier for the object.
- >- Identify the creator of each object when created.
- >- Be able to dump the data members of any object currently in existence.
- >- Be able to list all the objects currently in existence at any time.
- >
- >Has anyone had any experience with this? Are there already existing class
- >libraries or tools that do this sort of thing? I'd appreciate any ideas.
- >
- One way to achieve this is by defining a class with a static member and declaring an
- instance of the class in every class you want to debug. The constructor and destructor
- of the "trace" class give messages during creation and deletion.
-
- class Trace {
- private :
- static int ObjectCount;
- int id;
- public :
- Trace : id(++ObjectCount)
- {
- cout << "Constructing Object # "<< id << "\n";
- }
- ~Trace {
- cout << "Deleting Object # " << id << "\n";
- }
- };
-
- class MyClass {
- private :
-
- int MyData;
-
- #ifdef DEBUG_CLASS
- Trace MyTrace;
- #endif
-
- public :
- MyClass{};
- ...
- ...
- };
-
- This should help you to debug creation and deletion of objects.
-
- Shankar V
- ventura!vs@ucsd.edu
-
-
-
-