On Borrow Checking
claptrap
clap at trap.com
Sun May 18 12:20:54 UTC 2025
On Saturday, 17 May 2025 at 14:03:05 UTC, Richard (Rikki) Andrew
Cattermole wrote:
>
> On 17/05/2025 10:05 PM, claptrap wrote:
>>
>> Why is safe ref counting not feasible with D?
>
> Because we don't have a borrow checker.
>
> Any kind of pointer originating from the ``this`` pointer of a
> RC type, must not outlive the RC owner.
We have the same problem with manual memory management don't we?
So is "safe manual memory management" considered not possible in
D?
>> Wouldn't the fact that most data is thread local in D mitigate
>> the majority of the performance penalties? You dont need
>> atomic inc/dec if its thread local do you?
>
> I evaluated this ages ago, with a simple bit of value tracking
> + moving the reference add into the called function, you can
> get rid of a ton of those deltas.
>
> Anyway, atomic add/sub have gotten much cheaper on recent
> hardware, like 1uop. Still good to optimize unnecessary work
> away though!
Well the cost is irrelevant IMO, I mean people who dont want to
pay it choose a different solution, that seems to be a core idea
of Dlang, gc, nogc, betterc, etc..
D should be able to do reference counting, that it can't shows
failings in the language design.
More information about the Digitalmars-d
mailing list