Idea #1 on integrating RC with GC

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Feb 5 14:20:09 PST 2014


On 2/5/14, 12:35 PM, Dmitry Olshansky wrote:
> 05-Feb-2014 03:51, Andrei Alexandrescu пишет:
>> Consider we add a library slice type called RCSlice!T. It would have the
>> same primitives as T[] but would use reference counting through and
>> through. When the last reference count is gone, the buffer underlying
>> the slice is freed. The underlying allocator will be the GC allocator.
>>
>> Now, what if someone doesn't care about the whole RC thing and aims at
>> convenience? There would be a method .toGC that just detaches the slice
>> and disables the reference counter (e.g. by setting it to uint.max/2 or
>> whatever).
>>
>> Then people who want reference counting say
>>
>> auto x = fun();
>
> How abut just adding a template argument that indicates which container
> type to use for internal allocation?
>
> Array!T a = fun!(Array)(); //Ref-counted
> T[] a = fun(); //default args - GC
>
> IMHO solves Phobos side of equation.

Good idea.

Andrei



More information about the Digitalmars-d mailing list