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