COW vs. in-place.

Sean Kelly sean at f4.ca
Thu Aug 3 08:06:12 PDT 2006


Reiner Pope wrote:
>> Why not:
>>
>>     str = toupper(str);     // in-place
>>     str = toupper(str.dup); // COW
> 
> This is not copy on write. That is simply 'always copy', and this 
> performs worse than COW (which in turn performs worse than in-place, if 
> in-place is possible). Walter has also said earlier that, with COW, it 
> should be the responsibility of the writer to ensure the copy, not the 
> caller.

To do true COW, toupper would have to test every element against its 
uppercase equivalent--the first diff would cause a copy to occur.  For 
mutating algorithms such as this, I think it makes more sense for them 
to always change the data in place if possible and to document them as such.


Sean



More information about the Digitalmars-d mailing list