home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!mundil.cs.mu.OZ.AU!fjh
- From: fjh@mundil.cs.mu.OZ.AU (Fergus James HENDERSON)
- Subject: Re: Reference counting for vectors, (Tony Hansen's book).
- Message-ID: <9222811.20635@mulga.cs.mu.OZ.AU>
- Sender: news@cs.mu.OZ.AU
- Organization: Computer Science, University of Melbourne, Australia
- References: <1992Aug14.164719.9719@wuecl.wustl.edu> <BRISTER.92Aug14110706@tirade.decwrl.dec.com> <TMB.92Aug14232208@arolla.idiap.ch> <BRISTER.92Aug14170213@tirade.decwrl.dec.com>
- Date: Sat, 15 Aug 1992 01:46:25 GMT
- Lines: 29
-
- brister@decwrl.dec.com (James Brister) writes:
-
- >On 15 Aug 92 03:22:08 GMT, tmb@arolla.idiap.ch (Thomas M. Breuel) said:
- >> 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.
- >
- >If the array copies itself the first time it is written to, then you don't
- >loose anything except on the first access, and with large data it would be
- >better to have COW than to duplicate everything to protect against
- >unintended changes.
-
- You lose on every access, since you must *check* to see if the COW flag has
- been set. Some of the time a clever compiler may be able to optimize away
- that check, but it general it is unavoidable.
-
- Eg. (simplified):
-
- inline int& COW_Array::operator[](int i) {
- if (this->theArray->needs_to_be_copied()) // this is the test
- this->do_copy(); // you want to avoid
- return this->theArray->data[i];
- }
-
- --
- Fergus Henderson fjh@munta.cs.mu.OZ.AU
- This .signature VIRUS is a self-referential statement that is true - but
- you will only be able to consistently believe it if you copy it to your own
- .signature file!
-