Generic copy-on-write infrastructure in boost?

Hi, I'm looking for a way to implement a project using some copy-on-write feature, similar to how STL strings use reference counters to prevent needles copying of data. Is there anything in boost to help me out with this? -Jason ---------------------------------- Check out the Barracuda Spam & Virus Firewall - offering the fastest virus & malware protection in the industry: www.barracudanetworks.com/spam

On Wed, 12 Aug 2009 18:09:39 -0700, Jason Dictos <jdictos@barracuda.com> wrote:
I'm looking for a way to implement a project using some copy-on-write feature, similar to how STL strings use reference counters to prevent needles copying of data. Is there anything in boost to help me out with this?
If I understand correctly, what you need is something that passes the pointer along of the object, and when a non const operation is performed on the object, a "clone" like method is called? I guess you could rework shared_ptr, and have a .get() const and a .get() non const. When the refcount is 1, .get() does not clone. Is that what you need? ps : I'm curious, why do you need copy on write? -- EA

Essentially what we want to do is have a heap ptr class that can be copied around easily, without incurring the continual cost of duplicating the heap space on each copy operation. So we could for instance return this class directly on the stack from a method, and it would not consume additional heap ptrs, as the data would not have changed between each copy constructor, merely a reference count would be toggled a bit. Really almost exactly like an STL string (Assuming COW was being used of course), except it would hold binary safe data. -Jason -----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Edouard A. Sent: Thursday, August 13, 2009 1:50 AM To: boost@lists.boost.org Subject: Re: [boost] Generic copy-on-write infrastructure in boost? On Wed, 12 Aug 2009 18:09:39 -0700, Jason Dictos <jdictos@barracuda.com> wrote:
I'm looking for a way to implement a project using some copy-on-write feature, similar to how STL strings use reference counters to prevent needles copying of data. Is there anything in boost to help me out with this?
If I understand correctly, what you need is something that passes the pointer along of the object, and when a non const operation is performed on the object, a "clone" like method is called? I guess you could rework shared_ptr, and have a .get() const and a .get() non const. When the refcount is 1, .get() does not clone. Is that what you need? ps : I'm curious, why do you need copy on write? -- EA _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost ---------------------------------- Check out the Barracuda Spam & Virus Firewall - offering the fastest virus & malware protection in the industry: www.barracudanetworks.com/spam

On Thu, 13 Aug 2009 08:01:24 -0700, Jason Dictos <jdictos@barracuda.com> wrote:
Essentially what we want to do is have a heap ptr class that can be copied around easily, without incurring the continual cost of duplicating the heap space on each copy operation. [...] Really almost exactly like an STL string (Assuming COW was being used of course), except it would hold binary safe data.
References won't help in your case? I may also point you to pool_allocator in boost, that's going to reduce very much the cost of allocating and deallocating objects. Someone in the mailing list pointed out quite correctly that COW is not a very good idea on a 2009 system. I think in one of Sutter's book the COW is benchmarked and it's slower than non-COW. As for memory usage reduction, pool allocation is better suited. -- EA

Jason Dictos wrote:
I'm looking for a way to implement a project using some copy-on-write feature, similar to how STL strings use reference counters to prevent needles copying of data. Is there anything in boost to help me out with this?
*Some* implementations of the STL use (or used) COW strings. That is by no means ubiquitous. Are you aware that reference counting is a pessimization rather than an optimization in the presence of multiple threads for many cases? The locking overhead required to effect reference counting is greater than the cost of copying in such cases. Without COW, other optimizations are possible such as the small object optimization, in which the data is held within the object when small enough and moves to the free store when too large. There has been some recent discussion on this list about such things, in fact. I'm not aware of anything that will help you implement COW, but I suspect you'd be better served by avoiding it on modern computers. _____ Rob Stewart robert.stewart@sig.com Software Engineer, Core Software using std::disclaimer; Susquehanna International Group, LLP http://www.sig.com IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Interesting point, this goes along with an article I was reading on Dr. Dobb's: http://www.ddj.com/cpp/184405453 I suppose some performance testing of my own is in order, as our application is heavily threaded. -Jason -----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Stewart, Robert Sent: Thursday, August 13, 2009 5:20 AM To: boost@lists.boost.org Subject: Re: [boost] Generic copy-on-write infrastructure in boost? Jason Dictos wrote:
I'm looking for a way to implement a project using some copy-on-write feature, similar to how STL strings use reference counters to prevent needles copying of data. Is there anything in boost to help me out with this?
*Some* implementations of the STL use (or used) COW strings. That is by no means ubiquitous. Are you aware that reference counting is a pessimization rather than an optimization in the presence of multiple threads for many cases? The locking overhead required to effect reference counting is greater than the cost of copying in such cases. Without COW, other optimizations are possible such as the small object optimization, in which the data is held within the object when small enough and moves to the free store when too large. There has been some recent discussion on this list about such things, in fact. I'm not aware of anything that will help you implement COW, but I suspect you'd be better served by avoiding it on modern computers. _____ Rob Stewart robert.stewart@sig.com Software Engineer, Core Software using std::disclaimer; Susquehanna International Group, LLP http://www.sig.com IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost ---------------------------------- Check out the Barracuda Spam & Virus Firewall - offering the fastest virus & malware protection in the industry: www.barracudanetworks.com/spam

Jason Dictos wrote:
Hi,
I'm looking for a way to implement a project using some copy-on-write feature, similar to how STL strings use reference counters to prevent needles copying of data. Is there anything in boost to help me out with this?
-Jason
---------------------------------- Check out the Barracuda Spam & Virus Firewall - offering the fastest virus & malware protection in the industry: www.barracudanetworks.com/spam
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Check out Flyweight which was made a part of Boost in Version 1.38. As far as optimizations, Boost already have shared_ptr enhancements that are undergoing standardization where the control block is merged with the object pointed to; whether or not Flyweight takes advantage of this is a different matter. The only thing missing is the small object optimization.

On Thu, Aug 13, 2009 at 7:33 AM, Jarrad Waterloo<jwaterloo@dynamicquest.com> wrote:
Jason Dictos wrote:
Hi,
I'm looking for a way to implement a project using some copy-on-write feature, similar to how STL strings use reference counters to prevent needles copying of data. Is there anything in boost to help me out with this?
-Jason
As frequently happens, if Boost hasn't done it, Adobe ASL has: http://stlab.adobe.com/classadobe_1_1version__1_1_1copy__on__write.html Zach
participants (5)
-
Edouard A.
-
Jarrad Waterloo
-
Jason Dictos
-
Stewart, Robert
-
Zach Laine