Boost logo

Boost :

From: Caleb Epstein (caleb.epstein_at_[hidden])
Date: 2006-05-19 16:46:19


On 5/19/06, Pavel Vozenilek <pavel_vozenilek_at_[hidden]> wrote:

> If a read-write lock will be added it should be optional - the overhead may be too big.
>
> It should be also possible to _manually_ trigger the cloning:

The Adobe Open Source libraries have a copy_on_write<T> that
implements this nicely. There is a method called write() which
triggers the copy operation and returns a ref to the newly cloned
object. The copy is only performed if there is more than one
reference to the object.

adobe::copy_on_write<int> first (42);
adobe::copy_on_write<int> second (first);
assert (first.identity (second)); // same object
first.write() = 56; // a copy is made, and a ref to it is returned
assert (!first.identity(second));
assert (first.unique_instance());
assert (second.unique_instance());
first.write() = 42; // no copy, since first is a unique instance

http://opensource.adobe.com/classadobe_1_1copy__on__write.html

-- 
Caleb Epstein
caleb dot epstein at gmail dot com

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