Want reasonable reference counting? Disable automatic sharing of immutable
Elronnd
elronnd at elronnd.net
Mon Nov 15 02:18:46 UTC 2021
On Sunday, 14 November 2021 at 21:59:23 UTC, Timon Gehr wrote:
>> I assumed that 'outside of the type system' meant
>> 'language-level support for reference counting'; a a type with
>> opaque representation, like a hash table.
>> ...
>
> Yes, I guess that's another way to go about it, but I think
> less language magic is better. Especially with reference
> counting, you may want to have detailed control over the
> allocator and/or the strategy for storing reference counts.
Definitely agree!
That said I think there may be a middle ground, involving some
magic but also some control. In particular, compared with
__mutable, language-level support for intrusive rc can be sound
without leading to surprising results, as long as you're not
allowed to read from the reference count. Saying 'build me a
reference-counted object from this chunk of memory' should be
pretty easy, and ditto specifying how the memory is disposed of
once the reference count reaches 0. Being polymorphic over
intrusive/extrusive representation is harder, though.
More information about the Digitalmars-d
mailing list