gcc-2.95 and SGI STL 3.2

Joe Buck jbuck@Synopsys.COM
Fri Jun 25 09:44:00 GMT 1999


> On 21 Jun 1999, Steinar Bang wrote:
> 
> > The native g++ <string> uses refcounting.  The SGI STL <string> always
> > does a deep copy.
> 
> I don't think refcounting actually helps much with strings -- you have to
> do a deep copy whenever the data is accessed anyway (even read: think
> 'string s="str",t; char &c=s[0];').

You are not correct, you don't have to do a deep copy whenever the data
is accessed.  On a writable string, using begin(), end(), or [] on a
string with multiple references will require a deep copy.  However, those
same operations on a const string& will not require a copy, and
furthermore there are many other ways to access string data that don't
need a copy.  So in practice, programs that use strings a lot typically
have many references to the same string representation object (including
most of what I've written).  Switching to the SGI scheme would have
a substantial cost.




More information about the Gcc mailing list