RFC: safe ref counting

ikod geller.garry at gmail.com
Sat May 2 20:28:25 UTC 2020


On Saturday, 2 May 2020 at 18:23:36 UTC, Steven Schveighoffer 
wrote:
> 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?

Yes there is no magic and there are lot of limitations and 
inconveniences, but at least I know where data can leak.

Here is gist with code sample and comments: 
https://gist.github.com/ikod/2c35851581b59677a0d9511812592df0

>
> -Steve




More information about the Digitalmars-d mailing list