home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12366 < prev    next >
Encoding:
Text File  |  1992-08-14  |  1.8 KB  |  41 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!mundil.cs.mu.OZ.AU!fjh
  3. From: fjh@mundil.cs.mu.OZ.AU (Fergus James HENDERSON)
  4. Subject: Re: Reference counting for vectors, (Tony Hansen's book).
  5. Message-ID: <9222811.20635@mulga.cs.mu.OZ.AU>
  6. Sender: news@cs.mu.OZ.AU
  7. Organization: Computer Science, University of Melbourne, Australia
  8. References: <1992Aug14.164719.9719@wuecl.wustl.edu>     <BRISTER.92Aug14110706@tirade.decwrl.dec.com>     <TMB.92Aug14232208@arolla.idiap.ch> <BRISTER.92Aug14170213@tirade.decwrl.dec.com>
  9. Date: Sat, 15 Aug 1992 01:46:25 GMT
  10. Lines: 29
  11.  
  12. brister@decwrl.dec.com (James Brister) writes:
  13.  
  14. >On 15 Aug 92 03:22:08 GMT, tmb@arolla.idiap.ch (Thomas M. Breuel) said:
  15. >> Copy-on-write is not really an option for classes like arrays that
  16. >> require high-performance updates. You don't want to pay the price for
  17. >> the memory fetch and conditional branch on each array store.
  18. >
  19. >If the array copies itself the first time it is written to, then you don't
  20. >loose anything except on the first access, and with large data it would be
  21. >better to have COW than to duplicate everything to protect against
  22. >unintended changes.
  23.  
  24. You lose on every access, since you must *check* to see if the COW flag has
  25. been set. Some of the time a clever compiler may be able to optimize away
  26. that check, but it general it is unavoidable.
  27.  
  28. Eg. (simplified):
  29.  
  30.     inline int& COW_Array::operator[](int i) {
  31.         if (this->theArray->needs_to_be_copied())    // this is the test
  32.         this->do_copy();            // you want to avoid
  33.         return this->theArray->data[i];
  34.     }
  35.  
  36. -- 
  37. Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
  38. This .signature VIRUS is a self-referential statement that is true - but 
  39. you will only be able to consistently believe it if you copy it to your own
  40. .signature file!
  41.