Boost logo

Boost :

Subject: Re: [boost] [submission] STL-compliant containers with copy-on-write
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2011-03-31 15:30:57


On 31/03/2011 21:19, Alexandr Sterligov wrote:

> 1. Cache returns cached objects "by value" - this means that objects are
> copied.

Returning by value does not necessarily mean copying.
It can mean "nothing" (if the returned object is local to the function
and is used to initialize another object) or "move" (if the returned
object is local to the function or is moved from elsewhere).

> -: Cache is read 100-1000 times more often then written. That's usual. We
> can avoid 100-1000 copies.
> +: almost no synchronization is needed.
>
> 2. Cache returns pointer or reference. No copying.
> +: no copying, no memcpy...
> -: very hard synchronization in case if cache is written. Pointer from cache
> is finally put to another thread (GUI even loop), so only const pointer or
> reference may be returned from cache and it makes code in the GUI more
> complex - we need to copy data before we'd like to change anything. It
> starts to look like "external" COW.

Which is probably really what you want. A COW layer built on top.
Actually, your whole cache idea really looks like Boost.Flyweight,
except the latter purposely disallows mutability.

> Another situation is inside high-performance streaming library (TVoIP
> conference) - there are chain of filters which process media packets in
> conveyor manner. Filters are developed separately and may work inplace, or
> defer packets to process them later. If there is no COW, filters should
> always copy packets for deferring or inplace modification.

Or you could simply move them.


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