Reference counted containers prototype

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Dec 27 07:15:24 PST 2011


On 12/27/11 2:24 AM, Jonathan M Davis wrote:
> On Monday, December 26, 2011 20:47:50 Andrei Alexandrescu wrote:
>> 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?
>
> I'd be inclined to argue that reference counting and COW should be kept
> separate as opposed to being different versions of the same type simply to make
> it easier to understand. Not to mention, how often is COW needed for
> containers? It's useful for many things, but it's only useful for value-type
> containers, and the use cases for value-type containers are fairly limited I
> should think. I'm sure that they're very useful under certain circumstances,
> but as has been pointed out in the past, the fact that C++ defaults to having
> value-type containers is a big problem. So, I don't think that it's a bad
> thing to make it possible to have value-type containers and/or COW containers,
> but if they're going to seriously complicate things, then they should be
> separate IMHO. They're more specialized as opposed to being the normal use
> case.

Someone coming from C++ would instantly recognize value containers, and 
might prefer using them in spite our judgment that reference containers 
are preferable. COW is a great bridge because it keeps the copy 
constructor cheap.

> By the way, I'm surprised to see the use of delete in that code, since delete
> is supposed to be going away.

It's just a prototype.


Andrei


More information about the Digitalmars-d mailing list