This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: COW strings in libstdc++


Christopher Jefferson <chris@bubblescope.net> writes:
> On 31 Aug 2009, at 18:44, Brendan Miller wrote:
>
>> It looks like the current implementation of string in libstdc++ is
>> copy on write correct? Is this also true of gcc 3.4? Is this behavior
>> guaranteed for the future, or will C++0x somehow require a change
>> here?
>>
>> Generally I'm wondering whether it will remain efficient to do things
>> like stick strings by value in vectors to be sorted. Right now as I
>> see it, there's no real point in wrapping the string in a shared_ptr,
>> since it already uses reference counting internally.
>
> With some care, rvalue references will get back all the speed, and
> more, of COW in many situations. running std::sort on a vector of
> strings will be faster in C++0x with non-COW strings than C++03 with
> COW strings. Of course sometimes you actually want to copy of a
> string, and that will be slower.

It will be very important to make libstdc++ user's aware of the
performance implications when non-COW strings become the default.

Years ago, our RTOS vendor switched from libstdc++ to Dinkumware as
their default C++ library.  This resulted in in a substantial
performance regression in the product I was working on at the time.
It turns out, we had been very sloppy and were passing strings by
value instead of const reference in many places.  It took some time 
to figure out, as the COW vs. non-COW string difference hadn't been
clear.

    --jtc

-- 
J.T. Conklin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]