Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!newsfeed.internetmci.com!uwm.edu!reuter.cse.ogi.edu!qiclab.scn.rain.com!gemstone.com!servio!servio!aland
From: aland@servio.slc.com (Alan Darlington)
Subject: Re: Deep copy in Smalltalk and Eiffel
Message-ID: <1996Apr8.180804.25461@slc.com>
Sender: news@slc.com (USENET News)
Nntp-Posting-Host: servio
Organization: GemStone Systems, Inc., Beaverton OR, USA
References: <4k0sh1$86a@newsgate.sps.mot.com> <316465BC.41C67EA6@eiffel.com>
Date: Mon, 8 Apr 1996 18:08:04 GMT
Lines: 20

Richard Bunbury <bunbury@eiffel.com> writes:
<snip> 
> I am not a Smalltalk expert but do seem to recall from a comp.lang.smalltalk
> FAQ of some time ago that deep copy does not work in the case of circular
> structures. Confirmation from experts may be needed.
<snip> 
That is correct, which is possibly why it is no longer supported by most
(all?) Smalltalk vendors.  However, it is not particularly difficult to
write one that does handle circular structures.  Just keep a dictionary
(IdentityDictionary works best) of copied objects (the key is object; the
value is object's copy).  If an object being deep-copied is a key in the
dictionary, use the dictionary's value.  Otherwise put a shallow copy in
the dictionary and have it deep-copy the original object into itself.
You have to be careful about when to initialize the dictionary, and you
may have to use multi-level dictionaries if performance becomes a problem
(as it will if an object has a sufficiently complex structure :-).

  Cheers,
  Alan
    (standard disclaimer)
