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

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!ogicse!mintaka.lcs.mit.edu!ai-lab!life.ai.mit.edu!tmb
  2. From: tmb@arolla.idiap.ch (Thomas M. Breuel)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Indirect container classes
  5. Message-ID: <TMB.92Dec22175450@arolla.idiap.ch>
  6. Date: 23 Dec 92 01:54:49 GMT
  7. Article-I.D.: arolla.TMB.92Dec22175450
  8. References: <1992Dec20.232025.28984@county.oz.au>
  9. Reply-To: tmb@idiap.ch
  10. Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
  11.     Perceptive)
  12. Lines: 38
  13. NNTP-Posting-Host: arolla.idiap.ch
  14. In-reply-to: porum@county.oz.au's message of 20 Dec 92 23:20:25 GMT
  15.  
  16. In article <1992Dec20.232025.28984@county.oz.au> porum@county.oz.au (Peter Orum) writes:
  17.  
  18.    Could someone advise on what is the best method of
  19.    having a collection of pointers to large objects. The
  20.    large objects may appear on more than one list, but I
  21.    only want one instance of each object  to be created.
  22.  
  23.        a)    a list of pointers, eg List<String *>
  24.  
  25.        b)    a list class that assumes its  data are pointers
  26.            eg Indirect_List<String *>
  27.  
  28.        c)  use List<String>, but class String is implemented using
  29.            a pointer to a reference-counted String_rep.
  30.  
  31.    To  me,  method  a)  is  the easiest to implement but you lose
  32.    the  ability  to  test  for  list  membership  by  content, as
  33.    comparison is on absolute memory addresses.
  34.  
  35.    Method  b)  has  the  disadvantage  of (slightly) complicating
  36.    the   List   class, requiring  overloading  of  the  comparison
  37.    operators, search & copy functions.
  38.  
  39.    Method  c)  complicates the class definition, but means in the
  40.    client  code  I  don't have to decide on which type of List to
  41.    use, nor whether to use pointers or objects.
  42.  
  43.    What do other people do? 
  44.  
  45. Create a template class "Counted<T>" that gives you reference counted
  46. semantics for arbitrary objects "T". Then, use "List< Counted<String> >".
  47.  
  48. This is pretty close to your suggestion (c), but I think giving
  49. reference counted semantics to any type by default is a bad idea, so
  50. "String" should not be reference counted (it should be copied on
  51. assignment), while "Counted<String>" should be.
  52.  
  53.                     Thomas.
  54.