An exegesis of Walter's reference counted slice

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Tue Feb 24 13:10:10 PST 2015


On 2/24/2015 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.

Yes. I deliberately left that out in order to keep attention focused on the use 
of 'return ref'.


> Ironically, if those elements are references, but are reference counted
> references, then you wouldn't need to addRange. An interesting problem...

Correct, but (aside from the performance hit) it wouldn't be a bug to scan them 
unnecessarily in the GC.

One way is to have a scheme whereby, with introspection, a type can be 
determined to be ref counted. Then, using static if, doing the addRange would 
only be necessary if:

1. the element type contained indirections
2. those indirections were not ref counted


> I think a system of making sure a piece of data is always destroyed in the same
> thread it was created (unless of course, the thread is gone, in which case it
> doesn't matter), should be fine.

Yup, and I believe this is an orthogonal issue.



More information about the Digitalmars-d mailing list