home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12356 < prev    next >
Encoding:
Internet Message Format  |  1992-08-14  |  2.2 KB

  1. 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
  2. From: tmb@arolla.idiap.ch (Thomas M. Breuel)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Reference counting for vectors, (Tony Hansen's book).
  5. Message-ID: <TMB.92Aug14232208@arolla.idiap.ch>
  6. Date: 15 Aug 92 03:22:08 GMT
  7. References: <1992Aug14.164719.9719@wuecl.wustl.edu>
  8.     <BRISTER.92Aug14110706@tirade.decwrl.dec.com>
  9. Sender: news@ai.mit.edu
  10. Reply-To: tmb@idiap.ch
  11. Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
  12.     Perceptive)
  13. Lines: 35
  14. In-reply-to: brister@decwrl.dec.com's message of 14 Aug 92 18:07:06 GMT
  15.  
  16. In article <BRISTER.92Aug14110706@tirade.decwrl.dec.com> brister@decwrl.dec.com (James Brister) writes:
  17.  
  18.    On Fri, 14 Aug 1992 16:47:19 GMT, abed@venus.wustl.edu (Abed M. Hammoud) said:
  19.    > I was trying to implement the vector class using the method suggested
  20.    > by tony Hansen. i.e reference counting. the following code is taken
  21.    > from Hansen's book (C++ Answer book). There is some thing that doesn't
  22.    > seems correct.
  23.  
  24.    What's not correct? The fact that modifying one variable causes the other
  25.    to change? If that's not what you want, then this isn't for you, but in the
  26.    case where you're making multiple copies of the array (as paramaters to a
  27.    function, for example), then this scheme is great.
  28.  
  29. Using reference counting to get reference semantics on parameter
  30. passing is very confusing indeed (sadly, this bad idea seems to
  31. pervade the C++ literature).
  32.  
  33. I have found it to be much better to give everything (including
  34. arrays) value semantics and use call-by-reference when I want and mean
  35. call-by-reference (some special hacks are needed for avoiding
  36. redundant copies on return).
  37.  
  38. Using call-by-reference when you mean it is also more efficient than
  39. having reference counting operate behind the scenes constantly.
  40.  
  41. If you truly want reference counting semantics, you can easily derive
  42. it from objects with value semantics using a template class.
  43.  
  44.    [goes on to suggest the use of copy-on-write]
  45.  
  46. Copy-on-write is not really an option for classes like arrays that
  47. require high-performance updates. You don't want to pay the price for
  48. the memory fetch and conditional branch on each array store.
  49.  
  50.                     Thomas.
  51.