home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16696 < prev    next >
Encoding:
Text File  |  1992-11-21  |  1.9 KB  |  47 lines

  1. Newsgroups: cvnet.c++,comp.lang.c++
  2. Path: sparky!uunet!spool.mu.edu!darwin.sura.net!udel!rochester!rit!isc-newsserver!mpk9172
  3. From: mpk9172@ultb.isc.rit.edu (M.P. Kirby)
  4. Subject: Finding memory leaks
  5. Message-ID: <1992Nov20.191828.14500@ultb.isc.rit.edu>
  6. Originator: mpk9172@ultb
  7. Keywords: OOP,memory leaks
  8. Sender: news@ultb.isc.rit.edu (USENET News System)
  9. Nntp-Posting-Host: ultb-gw.isc.rit.edu
  10. Organization: Rochester Institute of Technology
  11. Date: Fri, 20 Nov 1992 19:18:28 GMT
  12. Lines: 33
  13.  
  14. In C I used to use a memory leak finder that would help me find
  15. my memory leaks.  I basically created a #define for malloc that redefined
  16. it to do:
  17.  
  18. #define malloc(size) (my_malloc(__FILE__,__LINE__,size)
  19.  
  20. This allowed me to maintain a list of all my memory allocations.  I would
  21. redefine free to be my_free to mark the element on the list as "freed."
  22. This allowed me to check to see what memory was outstanding at 
  23. different points in the program. (and at the end).  I would then be
  24. able to find out that a block of 300 k was allocated in file "stuff.c" at
  25. line 53.  This proved useful during the debuging stage.
  26.  
  27. I would like to do the same kind of thing in C++.  Unfortunately, it
  28. seems that new is not as easy to #define over as malloc.  I thought
  29. (briefly) that I could do something like #define new new(__LINE__,__FILE__) 
  30.  and then overload the new operator, but this causes a recursive macro.
  31.  
  32. Creating something that calls my_new doesn't work either.  Apparently the
  33. sytanx surround the new operator is special.
  34.  
  35. Is there anyway to do what I am trying to accomplish?  
  36.  
  37. Actually, What I would really want is a stack dump at every memory allocation.
  38. This way I would not only know that a block was allocated at a certain
  39. line number and in a file, but it was ordered by these people.  But I'm
  40. willing to take the easy way out.  Just knowing that I have a memory
  41. leak and where it is occuring is good enough.
  42.  
  43.  
  44. Mike Kirby
  45. mpk9172@ultb.isc.rit.edu
  46. Rochester Institute of Technology
  47.