From: red floyd on
On Apr 14, 4:38 pm, Daniel Kr�gler <daniel.krueg...(a)googlemail.com>
wrote:
> On 14 Apr., 20:44, s5n <sgb...(a)googlemail.com> wrote:
>
> > My question might be slightly off-topic, as it is specific to the STL
> > (and in fact specific to implementation-defined features), but this is
> > the best place i know to ask...
>
> The question is not off-topic at all.
>
> > std::string typically uses reference counting and CoW to reduce real
> > allocations to a minimum. i understand that this is an implementation-
> > defined detail, not standardized, but in my experience STL
> > implementations do this.
>
> Yes, this is a valid implementation technique for C++03,
> but no longer valid for C++0x. Todays implementations often
> take advantage of the small-string optimization, though.
>
>

Why is CoW no longer valid for C++0x? Is it due to move semantics?


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Daniel Krügler on
On 16 Apr., 00:33, red floyd <redfl...(a)gmail.com> wrote:
> On Apr 14, 4:38 pm, Daniel Kr�gler <daniel.krueg...(a)googlemail.com>
> wrote:

[..]

> > Yes, this is a valid implementation technique for C++03,
> > but no longer valid for C++0x. Todays implementations often
> > take advantage of the small-string optimization, though.
>
> Why is CoW no longer valid for C++0x? Is it due to move semantics?

The problem is, that the interface of basic_string
is not very well-designed for effective CoW implementations
(basically too many functions that would need to "unshare"
the string) and the fact that it looks like other
containers, but with very different invalidation
characteristics for iterator, references, and pointers.
This has lead to the observation that such a class
would be both too fragile for normal users and
would also prevent efficient usage of such a
fundamental class in multi-threaded code.

For more details I recommend to read the rationale
given in

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2534.html
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2647.html

HTH & Greetings from Bremen,

Daniel Kr�gler



--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Mathias Gaunard on
On 15 avr, 23:33, red floyd <redfl...(a)gmail.com> wrote:

> Why is CoW no longer valid for C++0x? Is it due to move semantics?

Move semantics make COW useless, but do not prevent it.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Andre Kaufmann on
Mathias Gaunard wrote:
> On 15 avr, 23:33, red floyd <redfl...(a)gmail.com> wrote:
>
>> Why is CoW no longer valid for C++0x? Is it due to move semantics?
>
> Move semantics make COW useless, but do not prevent it.

I think COW addresses another problem than move semantics.
If you assign one string to multiple other string instances,
COW strings will reference only one single string pointer.

While move semantics non COW strings will have the same content
copied multiple times.


Andre


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Mathias Gaunard on
On 17 avr, 23:06, Andre Kaufmann <akfmn...(a)t-online.de> wrote:

> I think COW addresses another problem than move semantics.

COW addresses the problem of when you copy while you don't need to.
It's basically a fix for broken code.

Move semantics allow you to not copy when you only need to move.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]