home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!mcsun!chsun!bernina!litsios
- From: litsios@iis.ethz.ch (James Litsios)
- Subject: Re: Dangling pointers & suggestions on future implementations of "delete"
- Message-ID: <litsios.727695594@iis>
- Sender: news@bernina.ethz.ch (USENET News System)
- Organization: Swiss Federal Institute of Technology (ETH), Zurich, CH
- References: <Jan18.210305.21697@yuma.ACNS.ColoState.EDU> <1993Jan19.193048.15022@borland.com> <1993Jan20.213807.20740@cbnewsi.cb.att.com>
- Date: Fri, 22 Jan 1993 09:39:54 GMT
- Lines: 54
-
- rhw@att.com (Robert Wentworth) writes:
-
- >For debugging purposes, I track down memory problems by overloading new
- >to store extra information with each object and overloading delete to
- >check/update this extra information. (Also add some code to allow other
- >checks).
-
- > ...
-
- >Anyone else have nifty techniques that they use to root out memory
- >problems?
-
-
- I have a new and delete redefinition package that essentially does the same
- thing with the added cappability of numbering each memory block. I then have
- a little input file in which I can set "break points" on specific memory
- blocks. For example:
-
- B A 2333
-
- specifies the when the memory block number 2333 is allocated and freed then
- call a predefined function. I then have a real debugger break point on this
- function with stops the execution of the program.
-
- This feature is really useful because if you run a program twice with the
- same input you get same numbering of the memory (this is not always true, but
- in that case you are in more trouble) so if you find something strange with
- a memory block you get its number and relaunch the program with a break point
- on that number you can then figure out when it was allocated, who is accessing
- it and if it is being freed too early. I use this to find memory leaks by
- adding break points to all memory block that still exist at the end of an
- execution, I relauch the program and it stops on each allocation that has
- no deallocation.
-
- Right now I redefine the new and delete operator, but I currently feel very
- insecure about this methode because if you redefine the new but not the delete
- or the delete but not the new you can end up with more trouble than you had in
- the first place. I now believe that short circuiting the malloc and free
- routines is a better way to go.
-
-
- >(I suppose I could provide a copy of my code for this, if anyone really
- >needs it.)
-
- Yes, people do need it. People do not realize how useful this type of tool
- is and how much time you gain debugging your code.
-
- James Litsios
-
- --
- James Litsios Phone: +41 1/256 49 50
- Integrated Systems Laboratory Fax: +41 1/252 09 94
- ETH Zurich E-Mail: litsios@iis.ethz.ch
- CH-8092 Zurich, Switzerland
-