pic11
pic11

Reputation: 15003

Boost shared_ptr: using unique() to implement copy on write

Could someone explain what boost shared_ptr manual means by this:

If you are using unique() to implement copy on write, do not rely on a specific value when the stored pointer is zero.

Thanks.

Upvotes: 3

Views: 898

Answers (2)

Puppy
Puppy

Reputation: 147054

Basically, what it means is that if you have a shared_ptr that doesn't point to anything, it might or might not say that it is unique. However, you should know that COW has been ditched by almost all major string libraries and disallowed for C++0x because it sucks, basically, so you want to be careful about doing this.

Upvotes: 4

Potatoswatter
Potatoswatter

Reputation: 137960

Copy-on-write is a storage scheme where copies of an object with duplicate values are represented by a single object. Only when you try to change one is it copied to a new, unique object.

Boost supports this by telling you whether a given shared_ptr is supporting more than one reference. If it is, then writing to the object will require making a copy.

The manual is saying that if you have NULL pointers in such a scheme, they might report being either unique or not. Really, Boost is being generous by even allowing such an operation.

Upvotes: 6

Related Questions