RFC: safe ref counting
Steven Schveighoffer
schveiguy at gmail.com
Sat May 2 20:51:07 UTC 2020
On 5/2/20 4:28 PM, ikod wrote:
> 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
>
OK, so essentially you need to have a lot of trusted escapes. I'm
looking for something that doesn't need that by default for useful code.
Though that does look correct in terms of memory safety.
My biggest problem with doing something like that is that for instance,
an iopipe buffered output stream uses reference counting to ensure that
once all references to the output stream are done, the final data in the
buffer is flushed to the output. This is a perfect fit for reference
counting, but of course, it can't be made @safe because iopipe provides
direct buffer access (that is part of the design).
So I want something @safe that provides direct buffer access, and also
can clean up whatever needs cleaning synchronously (e.g. closing files,
flushing data, etc). Developers are not going to be keen to a buffered
file flushing it's buffer at sometime in the future (or never).
AND I would like it to be storable inside a GC block (many people don't
realize that std.typecons.RefCounted isn't valid to put in the GC when
you have multiple threads).
-Steve
More information about the Digitalmars-d
mailing list