home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!stanford.edu!apple!applelink.apple.com
- From: D4887@AppleLink.Apple.COM (Advanced Comm Eng, G G Apple,PRT)
- Newsgroups: comp.sys.mac.oop.macapp3
- Subject: Re: Bug In TDynamicArray (MA3.
- Message-ID: <724463313.7767378@AppleLink.Apple.COM>
- Date: 15 Dec 92 23:43:00 GMT
- Sender: daemon@Apple.COM
- Organization: AppleLink Gateway
- Lines: 50
-
-
-
- ----------------------------------------------------------------------------
- >The problem arises when a TDynamicArray is cloned while an Iterator which was
- >used for the TDynamicArray is stil in scope. TDynamicArray has a field named
- >fIteratorPtr, which contains a linked list of Iterators currently in use for
- >the TDynamicArray. When a TDynamicArray gets cloned, both (the old and the
- >cloned Array's) fIteratorPtrs point to the same Iterator. If the
- >CArrayIterator
- >is destructed, the fIteratorPtr of the cloned TDynamicArray points to an
- >invalid Memory-Address.
-
- By golly, you're right! How they ever let one this obvious slip through
- I'll never know. TDynamicArray should have a Clone override that sets
- fIteratorPtrs = NULL.
-
- What the heck are you doing that creates a clone of the array while you're
- iterating it? It seems to me that the only time that linked list of iterators
- get used is when iterations are nested -- unless you are instantiating
- iterators as seperate objects and not by the usual method on the stack.
-
- My other comment would be the same that I usually give to people that ask
- me about subclassing, cloning, or file-storing TList and other such
- TDymamicArray thingies: "DON'T DO THAT". Usually, these things are used by
- (referenced by) other objects which are what you really want subclassed,
- cloned, or stored. Let their clone methods do the work. Also, note that
- cloning the TDynamicArray does NOT clone the objects refered to in the array.
-
- For example, I usually create my own list classes which encapsulate TList
- with my own functionality. When I want to clone something that has a
- referenced TList, I always let the encapsulating object ask for a new list and
- then, in the clone method of my object, iterate the cloned list to add all of
- the old elements to the clone list. That process creates a clone of the list,
- but not of the contents (elements) of the list (i.e., the new list has
- references to all the old elements). If you really want a deep clone (a
- seperate new list with its own new elements) then you must clone each element
- and add its clone to the clone list rather than adding the old elements.
-
- I guess that explains why I (and others) never ran into the problem you
- found.
-
- G. Gordon Apple D4887
- Advanced Communications Engineering, Inc.
- Redondo Beach, CA
-
- ------ Where we are not having any floods, hurricanes, blizzards, freezing,
- volcanic eruptions, famines, or tidal waves -- just the usual earthquakes and
- riots. I think I'll go for a walk on the beach (two blocks away) in my shirt
- sleeves this afternoon.
-
-