Reference counted containers prototype

Martin Nowak dawg at dawgfoto.de
Mon Dec 26 23:32:51 PST 2011


On Tue, 27 Dec 2011 03:47:50 +0100, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> On 12/26/11 11:25 AM, Andrei Alexandrescu wrote:
> [snip]
>> Destroy.
>
> Walter indeed just destroyed me over the phone: I conflated reference  
> counting with copy-on-write. Essentially instead of defining a reference  
> type that's garbage-collected, I defined a value type that has cow.
>
> Which is not bad! Check out the quick fix at  
> http://pastebin.com/HHw06qrc.
>
> With that, cow is a sheer policy. With the magic of opDispatch it looks  
> like we can define reference counted containers _and_ value containers -  
> all in very little code.
>
> The perspectives here are extremely exciting. The question remains how  
> to best package this awesome array of options to maximize coherence. So  
> we have:
>
> 1. "Basic" containers - reference semantics, using classic garbage  
> collection
>
Creating a final class wrapper using opDispatch and a value container
as a field might be an option that mixes well with the other wrappers.

> 2. Reference counted containers - still reference semantics, using  
> reference counting
>
Can't this be merged with std.typecons.RefCounted?

> 3. COW containers - value semantics, using reference counting to make  
> copying O(1).
>
If it works correctly this is a fully transparent COW wrapper, never seen  
anything like that in C++.
It deserves to be a separate wrapper in std.typecons or so.

> How to we provide an Apple-style nice wrapping to all of the above?
>
>
> Andrei
>
>
Implementing containers as value types with deep-copy and
providing the three wrappers seems the most flexible approach.
The are applications where values are sufficient, e.g. global lists.

for the naming:
struct DListImpl; // public
alias ClassWrapper!DListImpl DList;

optionally add aliases:

alias RefCounted!DListImpl RefCountedDList;
alias CopyOnWrite!DListImpl CopyOnWriteDList;

Given that it would be used consistently across the whole
std.container modules it's an easy scheme to learn.


More information about the Digitalmars-d mailing list