home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zephyr.ens.tek.com!uw-beaver!cornell!batcomputer!caen!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!deccrl!bloom-beacon!eru.mt.luth.se!lunic!sunic!seunet!appli!niklas
- From: niklas@appli.se (Niklas Hallqvist)
- Newsgroups: comp.lang.c++
- Subject: Re: Garbage Collection for C++
- Message-ID: <2135@appli.se>
- Date: 19 Aug 92 08:54:52 GMT
- References: <1992Aug6.014619.2111@ucc.su.OZ.AU> <DAVEG.92Aug13025629@synaptx.synaptics.com> <1992Aug14.021547.15215@news.mentorg.com> <DAVEG.92Aug14194411@synaptx.synaptics.com> <2009@appli.se> <TMB.92Aug17204854@arolla.idiap.ch>
- Organization: Applitron Datasystem AB, GOTHENBURG, SWEDEN
- Lines: 53
-
- tmb@arolla.idiap.ch (Thomas M. Breuel) writes:
-
- >niklas@appli.se (Niklas Hallqvist) writes:
-
- > I just wanted to say that conservative GC won't really help in all
- > situations. Jonathan Shapiro taught me this useful trick once.
- > When you want to do a doubly linked list to the cost of a singly
- > linked one (i.e. in mem. space). Instead of having two pointers
- > for the link in each node, take the "previous" and "next" pointers
- > and XOR them, and store the result!
-
- > Now you just need to store two entry consecutive points into the
- > list, and make an iterator intelligent enough to work things out.
- > This is of course a very special trick, but it IS useful, and it
- > shows NO GC strategy always wins unless the programmer explicitly
- > can tell what objects are live/dead, but then again, we're back to
- > explicit memory management.
-
- >You didn't take that seriously, did you? In any case, it's an old hat
- >and it's unportable (*).
-
- Well, I did mean it seriously, in order to show C++ rules need to be changed
- to allow even conservative GC. It's only unportable between environments
- which don't have sufficiently sized integers to store pointers in. If you
- restrict your program to only work on more "normal" architectures it IS
- defined. Read ARM 5.4! Of course, this means conservative GC is
- implementable on architectures where no integer type can hold a void pointer,
- but otherwise it is NOT. Do I miss anything in my thinking?
-
- >Incidentally, there is a widely used, simple, efficient, more general,
- >and completely portable technique for getting the same kinds of
- >storage savings as with the XOR trick.
-
- Oh? I can't think of any completely portable transformation of two pointers
- into a single field where you can get one of the pointers back if you know
- the other. Subtraction, for example, is only defined if the pointers are
- pointing into the same array (ARM 5.7). Maybe I'm on a soapbox when I
- assume a doubly linked listnode must be able to encode TWO pointers.
- And "widely used"? I have read lots and lots of source for over ten years
- and I have obviously missed it. Please show us this trick!
-
- >(*) In C++, there is no guarantee that there exists an integral type
- >large enough to hold a pointer; ARM p.67-68.
-
- So you had read this section, and still think GC can be done, if the text isn't
- changed to something like:
-
- "All pointer to integer conversions and back are implementation defined."
- --
- Niklas Hallqvist Phone: +46-(0)31-40 75 00
- Applitron Datasystem Fax: +46-(0)31-83 39 50
- Molndalsvagen 95 Email: niklas@appli.se
- S-412 63 GOTEBORG, Sweden mcsun!seunet!appli!niklas
-