RFC: safe ref counting

Steven Schveighoffer schveiguy at gmail.com
Sat May 2 18:23:36 UTC 2020


On 5/2/20 2:16 PM, Steven Schveighoffer wrote:
> ikod has a good plan, don't give access to the actual data. But it falls 
> apart in practice, because then you can't use standard functions, 
> everything has to use reference counted pointers and arrays. Not only 
> that, but a generic library can easily give away the data without you 
> wanting it to. You have to be really cautious about how you use the 
> reference counting.

As an example, if you have something like:

struct S
{
    int[100] buf;

    @disable this(this);

    int[] opSlice() { return buf[]; }
}

Now, reference counting this struct, you can prevent direct access to 
the S instance, but just calling x[] now gives you naked access to the data.

How do you solve this issue in D and still make it @safe without using 
the GC?

-Steve


More information about the Digitalmars-d mailing list