Want reasonable reference counting? Disable automatic sharing of immutable

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Mon Nov 15 09:42:03 UTC 2021


On Monday, 15 November 2021 at 09:22:16 UTC, Dukc wrote:
> I think he meant from optimisation viewpoint. C++ `const` is so 
> weak that it can't be used for actual optimisations anyway, at 
> least usually.

You cannot assume a lot about the underlying C++ object that is 
accessed through a reference, that is true. But you can infer the 
constness of functions by static analysis.

The most critical const objects are lookup-tables and one should 
be able to establish those as immutable in C++ too, as they are 
const objects that are not accessed through a "remote" pointer.

> So no performance is lost because of `mutable`. In D the 
> compiler can make some assumption based on `const` and 
> `immutable`, so we lose some performance potential if we 
> implement `mutable`.

Maybe, although it is kinda the same as having a mutable object 
with mostly immutable fields.

So, I would think that could be covered by having a mechanism for 
inferring "full immutability"?




More information about the Digitalmars-d mailing list