Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2004-09-20 14:59:40


From: Alexander Terekhov <terekhov_at_[hidden]>
> Maxim Yegorushkin wrote:
> [...]
> > Here is the link: http://conststring.sourceforge.net/
>
> "The mutability of std::basic_string<> and its interface do not allow
> implementers to make it a lightweight value object with cheap copy
> operation through string representation sharing and copy-on-write
> technique while maintaining thread safety."
>
> This claim borders on blatant FUD. Claims to the extent that std::
> string is sorta "less thread-safe then char[]" don't hold water
> because there isn't non-const overload of operator[] for char[].

I think it's just saying that COW can make strings more efficient
in single-threaded applications, but it's a pessimization for
multithreaded applications. Thus, an implementation can provide
different versions of std::basic_string for ST versus MT builds,
it can use COW (with locking for MT), or it can eschew COW
altogether. The first choice is harder for the implementer, but
results in (potentially) the best performance in both cases. The
second is suboptimal in MT applications, and the third is
suboptimal in ST applications.

Using an immutable string ensures the best performance regardless
of platform and threading model, even if that is the same as the
performance of std::basic_string on select platform/threading
model configurations.

-- 
Rob Stewart                           stewart_at_[hidden]
Software Engineer                     http://www.sig.com
Susquehanna International Group, LLP  using std::disclaimer;

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk