开发者

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

开发者 https://www.devze.com 2023-02-26 13:34 出处:网络
Could someone explain what boost shared_ptr manual means by this: If yo开发者_如何学JAVAu are using unique() to implement

Could someone explain what boost shared_ptr manual means by this:

If yo开发者_如何学JAVAu are using unique() to implement copy on write, do not rely on a specific value when the stored pointer is zero.

Thanks.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号