home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!wupost!cs.utexas.edu!usc!sdd.hp.com!zaphod.mps.ohio-state.edu!think.com!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: Reference counting for vectors, (Tony Hansen's book).
- Message-ID: <TMB.92Aug14232208@arolla.idiap.ch>
- Date: 15 Aug 92 03:22:08 GMT
- References: <1992Aug14.164719.9719@wuecl.wustl.edu>
- <BRISTER.92Aug14110706@tirade.decwrl.dec.com>
- Sender: news@ai.mit.edu
- Reply-To: tmb@idiap.ch
- Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
- Perceptive)
- Lines: 35
- In-reply-to: brister@decwrl.dec.com's message of 14 Aug 92 18:07:06 GMT
-
- In article <BRISTER.92Aug14110706@tirade.decwrl.dec.com> brister@decwrl.dec.com (James Brister) writes:
-
- On Fri, 14 Aug 1992 16:47:19 GMT, abed@venus.wustl.edu (Abed M. Hammoud) said:
- > I was trying to implement the vector class using the method suggested
- > by tony Hansen. i.e reference counting. the following code is taken
- > from Hansen's book (C++ Answer book). There is some thing that doesn't
- > seems correct.
-
- What's not correct? The fact that modifying one variable causes the other
- to change? If that's not what you want, then this isn't for you, but in the
- case where you're making multiple copies of the array (as paramaters to a
- function, for example), then this scheme is great.
-
- Using reference counting to get reference semantics on parameter
- passing is very confusing indeed (sadly, this bad idea seems to
- pervade the C++ literature).
-
- I have found it to be much better to give everything (including
- arrays) value semantics and use call-by-reference when I want and mean
- call-by-reference (some special hacks are needed for avoiding
- redundant copies on return).
-
- Using call-by-reference when you mean it is also more efficient than
- having reference counting operate behind the scenes constantly.
-
- If you truly want reference counting semantics, you can easily derive
- it from objects with value semantics using a template class.
-
- [goes on to suggest the use of copy-on-write]
-
- Copy-on-write is not really an option for classes like arrays that
- require high-performance updates. You don't want to pay the price for
- the memory fetch and conditional branch on each array store.
-
- Thomas.
-