RFC: safe ref counting

Steven Schveighoffer schveiguy at gmail.com
Wed Oct 28 17:20:11 UTC 2020


On 10/27/20 7:55 PM, Eduard Staniloiu wrote:
> On Saturday, 2 May 2020 at 02:27:10 UTC, Steven Schveighoffer wrote:
>> In trying to make iopipe @safe, I came to the realization that having 
>> auto-managed items such as files and the like (std.io Files and 
>> Sockets are non-copyable), you need to rely on some form of @safe 
>> reference counting. Unfortunately std.typecons.RefCounted is not and 
>> cannot be safe. This is because it allocates in the C heap, and 
>> deallocates regardless of whether anyone has ever squirreled away a 
>> reference.
>>
>> [...]
> 
> I’m late to the party.
> 
> I think you could use one of the allocation schemes proposed by 
> Alexandru Jercaianu in his dconf talk [2]

Thanks, I had forgotten about this (you can see my bald head in the 
video, so I was there ;)

It's an interesting opportunity. Perhaps there is room for a RefCounted 
type that allows multiple memory allocation schemes. I think the concept 
I came up with back then is pretty solid, it's since been released in 
iopipe. That will possibly allow iopipes in @nogc code that need ref 
counting.

The concept is the same -- I want to synchronously clean up the type, 
but leave the memory for something else to clean up, or flag as an error.

-Steve


More information about the Digitalmars-d mailing list