Subject: Re: [boost] [smart ptr] Any interest in copy-on-write pointer for C++11?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2013-02-10 13:18:54
On 09/02/13 09:49, Ralph Tandetzky wrote:
> Under your assertions the STL is just as broken. For example
> std::vector<T>::push[_]back() might change the address of the contained
> data and therefore invalidate all pointers and iterators to it.
That is intrinsic to this data structure.
Modifying the size of a sequence is a whole other thing than modifying
> For client code of a class using cow_ptrs for data members internally it
> is even easier not to worry about making copies, but the class
> automatically does it for you. cow_ptr helps to implement that behaviour.
So you admit the only rationale for your cow_ptr is to support sloppy
Making everything slow and unnatural just to make it "easier for the user".
> It can be an implementation-specific detail and can make code faster
> without the client code knowing about it. But it can also be a thing the
> client code relies upon as with the Matrix class above. Sometimes client
> code might want to know, if copies can be made cheaply.
A client should never rely on copying not being a 0(n) operation,
because it is.
Don't want to copy? Don't copy.
Now if you want to add an option to turn your copies into copy-on-writes
to measure there is any performance gain, why not. But that's just a
pessimization that may become an optimization in certain cases, it's not
a general approach.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk