From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2005-06-01 09:39:50
Peter Dimov wrote:
> Alexander Terekhov wrote:
> > Maksym Motornyy wrote:
> >> Thanks for articles. Well, I understand that multithreaded
> >> environment can be a bad place for COW optimization.
> > That's a myth.
> It depends on the interface of the class. Returning pointers and references
> into the object is bad, as is const/non-const overloading where the
> non-const version can be used for read access.
Use const reference/const_cast<> for read access (and non-const
object) to avoid unwanted mutations.
> Non-const member functions of the begin()/end() variety are worse than just
> returning a single reference into the object, because you can't "copy on
> write" between the two, or they'll get out of sync.
Yeah, simply put, mutations of std::string object may invalidate
references and iterators (with COW inspired semantics for non-
const operator() et al. )... threads or no threads, COW or no
> Reference-counting immutable objects is fine, but COW can be a pain.
Only in wrong hands. ;-)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk