Enhancements can enable memory-safe reference counting
tsbockman
thomas.bockman at gmail.com
Thu May 27 00:57:51 UTC 2021
On Thursday, 27 May 2021 at 00:20:44 UTC, vitoroak wrote:
> The same happens for a Vector implementation where you can call
> push (that can reallocate) while having a reference to an
> element.
Although it's not shown in my earlier code example, I did
recognize the problem of reassignment/reallocation potentially
invalidating extant borrowed references in my full system. (But,
I missed the problem of manual destructor calls.)
My solution for reassignment/reallocation was simply to make
`opAssign`, unique move operations, etc. `@system`. Of course
this is a significant limitation, but I think there is still a
lot of value in a reference counting system if the rest of its
operations can be `@trusted`.
But, if the destructor has to be `@system` too, then it is no
longer possible to use the reference counting system for any
practical purpose in `@safe` code. For myself, I will just cheat
and leave the destructor `@trusted` anyway, because why would I
manually call it in `@safe` code to begin with? But, we'll need a
better answer than that for the standard library.
More information about the Digitalmars-d
mailing list