
On 3 May 2010, at 13:28, Stewart, Robert wrote:
Christopher Jefferson wrote:
On 3 May 2010, at 12:39, Stewart, Robert wrote:
Chad Nelson wrote:
algorithms that have to start with a copy of one or more of the passed-in parameters, but then need to modify it/them. The division algorithm requires this, just as one example off the top of my head.
If your algorithm requires a copy, then COW should make it slower because it will first manipulate the reference count and because you must query in each mutating operation whether to make a unique copy.
But, you save the cost of copying a large object. COW has many disadvantages, but how can you claim it is slower when you require a copy?
Did you miss the "but then need to modify it/them" part? The only reason for the copy was to have a mutable copy. Thus, the COW overhead was useless in that example.
Apologises, I did indeed not read the message closely enough. My experience from COW std::string implementation is that with care, rvalue references and copy elising, you can get away with almost no unnecessary copies. In particular, in C++0x having the compiler always move local variables in return statements is a big win. How much of this gain you would get in a plain C++03 compiler, with boost::move but without users annotating any moves or rvalues to their code, I don't know. Chris