An exegesis of Walter's reference counted slice

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Tue Feb 24 12:19:46 PST 2015


On Tue, 24 Feb 2015 12:03:36 -0800, Andrei Alexandrescu wrote:

> On 2/24/15 11:55 AM, Steven Schveighoffer wrote:
>> Note, you need to GC.addRange all the elements if the type has
>> references, or else you cannot have GC pointers in the array. For
>> example, an array of class references could potentially result in those
>> references being collected before the array is gone.
>>
>> Ironically, if those elements are references, but are reference counted
>> references, then you wouldn't need to addRange. An interesting
>> problem...
> 
> Could you please add a detailed issue about this? Thanks. -- Andrei

here's the fixed code: http://dpaste.dzfl.pl/5f7dfe237d1e

btw, you have a bug in your implementation:

  (cast(E*) malloc(a.length * uint.sizeof))[0 .. a.length])();

should be:

  (cast(E*) malloc(a.length * E.sizeof))[0 .. a.length])();

sorry, i'm bad in explanations, let the code speak for itself.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20150224/d15edaec/attachment.sig>


More information about the Digitalmars-d mailing list