home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / programm / 2050 < prev    next >
Encoding:
Internet Message Format  |  1992-07-22  |  2.1 KB

  1. Path: sparky!uunet!mcsun!uknet!mucs!m1!bevan
  2. From: bevan@cs.man.ac.uk (Stephen J Bevan)
  3. Newsgroups: comp.programming
  4. Subject: Re: Chasing memory leaks: tools, procedures?
  5. Message-ID: <BEVAN.92Jul21191607@panda.cs.man.ac.uk>
  6. Date: 21 Jul 92 18:16:07 GMT
  7. References: <1992Jul6.093355.20442@lth.se>
  8.     <1992Jul18.203518.14496@murdoch.acc.Virginia.EDU>
  9.     <1992Jul19.160323.8820@organpipe.uug.arizona.edu>
  10.     <NICKEL.92Jul19184631@desaster.cs.tu-berlin.de>
  11. Sender: news@cs.man.ac.uk
  12. Organization: Department of Computer Science, University of Manchester
  13. Lines: 32
  14. In-reply-to: nickel@cs.tu-berlin.de's message of 19 Jul 92 17:46:31 GMT
  15.  
  16. In article <NICKEL.92Jul19184631@desaster.cs.tu-berlin.de> nickel@cs.tu-berlin.de (Juergen Nickelsen) writes:
  17.    In article <1992Jul19.160323.8820@organpipe.uug.arizona.edu>
  18.    dave@cs.arizona.edu (Dave Schaumann) writes:
  19.  
  20.    > The definition of new is
  21.    > 
  22.    > #define new(type)  ( (type *)must_alloc(sizeof(type)) )
  23.    > 
  24.    > and must_alloc() is just a function that calls malloc and aborts if malloc
  25.    > returns NULL.
  26.  
  27.    To make this more useful, must_alloc() should also call some
  28.    cleanup-function. For some application it is a must to have control of
  29.    their termination, e.g. to remove temporary files, re-rename
  30.    temporarily renamed files etc.
  31.  
  32. Assuming you quit must_malloc with "exit", how about just registering
  33. your procedures with "atexit"?  Alternately, if you really want to
  34. keep the things separate, how about having a malloc specific "atexit"
  35. and allow multiple procedures to be registered?  It seems much more
  36. flexible to me.  Of course then you can have another function which
  37. allows you to remove registered routines (or at least the last defined
  38. one).  And then you can ....  anyone get the feeling exception
  39. handling is being reinvented for the nth time :-)
  40.  
  41. I've implemented some of the above in my own "must_malloc" variant,
  42. though I didn't go as far as a specific "atexit".  It has a few other
  43. niceties like creating a log file of all (de)allocations so you can
  44. check for leaks in your program.  I can make it available (by mail) if
  45. anybody is interested.
  46.  
  47. bevan
  48.