comp.lang.ada
 help / color / mirror / Atom feed
From: boehm@titan.rice.edu (Hans Boehm)
Subject: Re: From Modula to Oberon
Date: 30 Mar 88 22:41:07 GMT	[thread overview]
Message-ID: <628@ra.rice.edu> (raw)
In-Reply-To: 8196@sol.ARPA


  It seems to me that the C++ approach to storage management is at best
a partial solution.  Admittedly it succeeds at automatically deallocating
objects in trivial cases.  For some applications this is, no doubt,
sufficient.  But consider a case as simple as implementing a stack type,
whose underlying representation is a linked list.  Assume this type
includes a non-destructive "pop" operation that returns a new stack
one shorter than the old one.  The original stack is left intact.  ("Pop"
can of course be implemented as the "tail" operation on linked lists.)
Should the head of the original linked list be deallocated?  Is it reasonable
to make that the caller's responsibility?  Certainly not, since it's not
supposed to know anything about the representation of stacks.  After all,
I could be copying arrays.  The stack implementation could reference count,
but that's more tedious, error prone, and probably slower than a good
garbage collector.  It also doesn't always work.
  My experience is that any attempt at manipulation of interesting linked
structures in a language that doesn't support real automatic storage
management will either fail, or waste large amounts of debugging time.
(My experience includes a (working) 40,000 line compiler, written in C, that
manipulates a reference counted syntax "tree", or more accurately, a
reference counted syntax graph.)  Normally, it is extremely difficult
to track down bugs created by premature deallocation.  When such bugs are
finally removed, the resulting programs normally include a substantial
number of storage leaks.
  Some recent experiments by Mark Weiser and myself with retrofitting a
garbage collector to existing C programs, verify the latter point.
(The garbage collector should never free anything since that was the
programmers responsibility.  It does.  In other people's code.
Our paper on this should appear in Software P&E shortly.)
Mike Caplinger reported similar results for another application at the last
USENIX conference, I believe.  We have resurrected C code with storage
management bugs by linking it against a garbage collector (which in the case
of C doesn't always work either, but it has a better track record than manual
storage management).
  There are arguably cases in which a garbage collector is undesirable,
notably in the presence of severe real-time constraints.  But even in such
a situation, I would want a garbage collector during debugging to help
me track down storage leaks.

Hans-J. Boehm                       boehm@rice.edu
Computer Science Dept.
Rice University
Houston, TX 77251-1892

  reply	other threads:[~1988-03-30 22:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <145@krafla.rhi.hi.is>
     [not found] ` <272@fang.ATT.COM>
1988-03-29 13:47   ` From Modula to Oberon Denis Fortin
1988-03-30 15:32     ` Lawrence Crowl
1988-03-30 22:41       ` Hans Boehm [this message]
1988-03-31  6:27         ` Garbage Collection Richard Harter
1988-03-31 19:49           ` Hans Boehm
1988-04-01  5:43             ` Richard Harter
1988-04-01 18:43               ` Hans Boehm
1988-04-04 23:14           ` 00704a-Liber
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox