From -5196078196049085570
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,b83a4267f4ac775
X-Google-Attributes: gidf78e5,public
From: phalpern@truffle.ma.ultranet.com (Pablo Halpern)
Subject: Re: string/cow/algorithm
Date: 1998/08/21
Message-ID: <35dfe616.47271311@news.ma.ultranet.com>#1/1
X-Deja-AN: 383385775
X-NNTP-Posting-Host: truffle.ultranet.com
Content-Transfer-Encoding: 7bit
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <6qfr41$oue$1@pigpen.csrlink.net> <35ccc2b4.832003@news3.ibm.net> <6qn19u$sb0$1@pigpen.csrlink.net> <6qnfc9$a0s$1@nnrp1.dejanews.com> <6qovei$5ou$1@shell7.ba.best.com> <fxtu33jl9zt.fsf@isolde.engr.sgi.com> <6qqd2q$bs9$1@nnrp1.dejanews.com>
X-UID: 0000000001
X-Status: $$$T
X-Ultra-Time: 21 Aug 1998 03:53:28 GMT
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@ultra.net
Organization: UltraNet Communications , an RCN Company http://www.ultranet.com/
Mime-Version: 1.0
Newsgroups: comp.std.c++
Originator: clamage@taumet


AllanW@my-dejanews.com wrote:

>Maybe what we really should have done is require string to disallow
>looking at individual characters with char*-type notation; leaving
>only iterators. Then any library vendor could implement ref-counting
>simply by having the iterator return a proxy which triggers cow when
>appropriate. Programs that need char*-type notation wouldn't be
>affected, since they could still use array-of-char!
>
>But that doesn't help *now*, you point out? Granted. But what can we
>do now, short of avoiding ref-counting like the plague?

What we can do *now* is to use COW implementations that punt (do a
deep-copy and mark unsharable) when the caller uses (non-const)
operator[], begin(), or end().  My programs rarely use these features of
stings.  Most common operations on strings is copying, creating
substrings, replacing substrings, concatonating and displaying, all of
which can be done without marking a string buffer as non-sharable.
Replacing single characters is much rarer and can either be done using
replace(), or else suffer the performance penalty for using operator[]
or non-const iterators.

Thus a COW implementation can be just as efficient as you want, if use
use it *as if* the operations mentioned were forbidden.

-------------------------------------------------------------
Pablo Halpern                   phalpern@truffle.ultranet.com

I am self-employed. Therefore, my opinions *do* represent 
those of my employer.


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




