Future of SafeRefCounted
Dukc
ajieskola at gmail.com
Mon Feb 24 17:18:55 UTC 2025
On Sunday, 23 February 2025 at 20:02:03 UTC, Dennis wrote:
> On the other hand, I think reference counting sucks in general,
> and see little value in using it in Phobos. Especially in
> functions like dirEntires, as if that is going to be called a
> lot in performance critical real-time code.
I disagree, reference counting is a great tool for this use case.
Not because of the memory, but because if the directory handles.
Were the `dirEntries` implementation garbage collected, the
directory handles would get released only when the collection
happens, which could never happen if the program doesn't use much
RAM.
Admittedly this kind of reference counting doesn't mandate using
`SafeRefCounted` - the reference counter could just free the
directory handles and leave the RAM management to the GC, and
this would be totally `@safe`.
When I think of it, maybe `DirEntries` should have the
`SafeRefCounted` field as an untyped `void[x]` field instead and
have a manually written `@trusted` destructor to call the
`SafeRefCounted` destructor, so the ABI of
`dirEntries`/`DirEntries` isn't affected. Ironically this means
there's no benefit anymore from using `SafeRefCounted` over the
old `RefCounted`.
More information about the Digitalmars-d
mailing list