Want reasonable reference counting? Disable automatic sharing of immutable

Danni Coy danni.coy at gmail.com
Mon Nov 15 11:40:45 UTC 2021


On Mon, Nov 15, 2021 at 9:50 PM Elronnd via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On Monday, 15 November 2021 at 09:28:41 UTC, Danni Coy wrote:
> > rather than punching a hole in const/immutable
> >
> > struct S
> > meta {
> > int refCount;
> > ....
> > }
> > do {
> >  int payload;
> > ....
> > }
> >
> > Immutable S s is now conceptually an immutable object and a
> > mutable
> > object with metadata behind the scenes
> > that feels like a single object from a user perspective?
>
> That is functionally the same thing as '__mutable int refCount',
> discussed elsethread.

>From an implementation point of view maybe. It has the advantage of
having the linguistic model match what the compiler is doing behind
the scenes (making it easier to reason about / conceptualise).

Would it be possible to limit operation of the writeable components to
a small subset of the language which would allow the necessary
operations but remove a lot of the complications?


More information about the Digitalmars-d mailing list