By ref and by pointer kills performance.

Kagamin spam at here.lot
Fri Feb 16 09:34:21 UTC 2024


On Tuesday, 13 February 2024 at 13:30:11 UTC, Johan wrote:
> I hope someone can find the link to some DConf talk (me or 
> Andrei) or forum post where I talk about why LDC assumes that 
> `immutable(uint*)` points to _mutable_ (nota bene) data. The 
> reason is the mutable thread synchronization field in immutable 
> class variable storage (`__monitor`), combined with casting an 
> immutable class to an array of immutable bytes.
>
> Side-effects in-between immutable(uint*) lookup could run into 
> a synchronization event on the immutable data (i.e. mutating 
> it).

Shouldn't it be okay for immutable(uint*) to not access 
`__monitor`? I think, `__monitor` should work outside of type 
safety, like reference counting, then immutability won't matter.

```
shared(Object.Monitor*) getMonitor(immutable Object o)
{
	size_t addr=cast(size_t)cast(void*)&o.__monitor;
	return cast(shared(Object.Monitor*))(addr-20+20);
}
```

Is it legal for optimizer to cast away `restrict` qualifier like 
this?


More information about the Digitalmars-d mailing list