home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / mac / oop / macapp3 / 206 < prev    next >
Encoding:
Internet Message Format  |  1992-12-15  |  2.9 KB

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