Reference counted containers prototype

Michel Fortin michel.fortin at michelf.com
Mon Dec 26 21:28:51 PST 2011


On 2011-12-27 02:47:50 +0000, Andrei Alexandrescu 
<SeeWebsiteForEmail at erdani.org> said:

> 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
> 
> 2. Reference counted containers - still reference semantics, using 
> reference counting
> 
> 3. COW containers - value semantics, using reference counting to make 
> copying O(1).
> 
> How to we provide an Apple-style nice wrapping to all of the above?

Apple just doesn't give you this kind of options. It picks one for you, 
documents the semantics and keep the implementation opaque. Containers 
in Objective-C are regular objects, so they follow object semantics 
(not that I like it though).

Ideally for D we'd follow the natural language semantics, where the 
first would be a DList*, the second is a RefCounted!DList, and the last 
is a RefCopy!DList. The only "problem" is that the default 'DList' is a 
value-type and it seems you don't want that to be the default. 
Unfortunately, I don't think there is a clean way to solve this: there 
are just too many options, some who must be implemented by library 
types and another by a language type. Reminds me of Rebindable…

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d mailing list