home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18329 < prev    next >
Encoding:
Internet Message Format  |  1992-12-22  |  3.6 KB

  1. Path: sparky!uunet!gatech!usenet.ins.cwru.edu!agate!spool.mu.edu!umn.edu!csus.edu!netcom.com!netcomsv!ulogic!hartman
  2. From: hartman@ulogic.UUCP (Richard M. Hartman)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Indirect container classes
  5. Message-ID: <770@ulogic.UUCP>
  6. Date: 22 Dec 92 22:52:27 GMT
  7. References: <1992Dec20.232025.28984@county.oz.au> <1992Dec21.100339.14138@ucc.su.OZ.AU>
  8. Organization: negligable
  9. Lines: 77
  10.  
  11. In article <1992Dec21.100339.14138@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  12. >In article <1992Dec20.232025.28984@county.oz.au> porum@county.oz.au (Peter Orum) writes:
  13. >>Could someone advise on what is the best method of
  14. >>having a collection of pointers to large objects. 
  15. >>The
  16. >>large objects may appear on more than one list, but I
  17. >>only want one instance of each object  to be created.
  18. >>
  19. >>    a)    a list of pointers, eg List<String *>
  20. >>    
  21. >>    b)    a list class that assumes its  data are pointers
  22. >>        eg Indirect_List<String *>
  23. >>        
  24. >>    c)  use List<String>, but class String is implemented using
  25. >>        a pointer to a reference-counted String_rep.
  26. >>        
  27. >>To  me,  method  a)  is  the easiest to implement but you lose
  28. >>the  ability  to  test  for  list  membership  by  content, as
  29. >>comparison is on absolute memory addresses.
  30. >>
  31. >>Method  b)  has  the  disadvantage  of (slightly) complicating
  32. >>the   List   class, requiring  overloading  of  the  comparison
  33. >>operators, search & copy functions.
  34. >>
  35. >>Method  c)  complicates the class definition, but means in the
  36. >>client  code  I  don't have to decide on which type of List to
  37. >>use, nor whether to use pointers or objects.
  38. >
  39. >    c) looks most worth perusing to me. Without reference
  40. >counting (a or b), how do you plan to delete the large objects
  41. >when they are no longer required? (Or rather, how will
  42. >you know when they are no longer required?)
  43.  
  44. In my case I know because I add the object to all appropriate
  45. lists and remove it from all appropriate lists at the same
  46. time.
  47.  
  48. e.g. message comes in: register Student James Cagney, New York, Desk 6
  49.  
  50. I create the student object for James, and add it to
  51.  
  52.     a) the master student roster (sorted alphabetically)
  53.     b) the student roster for New York (indexed by Desk number
  54.         and also alphabetically)
  55.     c) for each list, it is also added to a hashing dictionary
  56.         so I can get straight to that student object from the
  57.         name (and can then increment from desk 6 to desk 7, or
  58.         get the next name alphabetically at New York, or from
  59.         the master roster)
  60.     d) POTENTIALLY added to a "wants to ask a question" queue
  61.  
  62. The point is, reference counting is not (in this case at least)
  63. neccessary, even though the object is used multiple times.  When
  64. it comes time to log Jimmy out, I *do* have to check to see if
  65. he has his hand raised, but other than that he comes out of all
  66. lists at the same time.
  67.  
  68. I do not have templates available.  I am using NIH-derived list
  69. classes for queues, priority queues, sorted lists etc.  The
  70. Student Object is derived from the good ol' NIH object class,
  71. with links being dynamically allocated for each list I wish
  72. to put him on.  I really, really dislike the idea of having
  73. to specially derive an object from a LinkObject class in order
  74. to put it on a list, a Link points to the next Link, and to
  75. it's "contents" which may be any Object-derived class.
  76.  
  77. This said, I don't know if it answers the original question,
  78. but it does answer the "how do you know when to delete the
  79. object if you don't use reference counters" question for at
  80. least one application.
  81.  
  82.         -Richard Hartman
  83.         hartman@uLogic.COM
  84.  
  85. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  86. "Ideas are not responsible for the people who believe them."
  87.  
  88.