Want reasonable reference counting? Disable automatic sharing of immutable

Timon Gehr timon.gehr at gmx.ch
Sun Nov 14 21:25:58 UTC 2021


On 14.11.21 21:46, H. S. Teoh wrote:
> On Sun, Nov 14, 2021 at 09:22:39PM +0100, Timon Gehr via Digitalmars-d wrote:
>> On 14.11.21 21:04, H. S. Teoh wrote:
>>>
>>> So, either (1) we cannot use const/in in generic functions, or (2)
>>> ref-counted objects cannot be used in generic code.
>>>
>>> Given D's emphasis on generic code, (1) seems like the only viable
>>> option.  Which makes const in D even narrower in scope than ever.
>>
>> I don't agree that it changes anything for generic code. `const`
>> already prevents useful patterns such as lazy initialization.
> 
> Yes, which already confines const to a very narrow scope indeed. And if
> we now make ref-counting require mutable, then const is basically
> relegated to the niche of niches, usable only for very narrow and
> specific use cases like const(char)[] or immutable(char)[] aka string.
> ...

Well, my point was, _this is the status quo_. we are not now "making" it 
anything. Of course, it's more likely that those who are unaware will 
notice it if reference counting is popularized as a memory management 
strategy. I guess this was your point.

Interestingly, std.typecons.RefCounted "works" with const objects, but 
that's only because postblit is unsound.


More information about the Digitalmars-d mailing list