By ref and by pointer kills performance.

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Tue Feb 13 19:11:25 UTC 2024


On 14/02/2024 4:14 AM, Patrick Schluter wrote:
> Is not a thread issue. The memory the pointers point to only needs to 
> overlap and the loads are required to get the "right" result.

It can be a thread issue, but yes overlapping is another potential 
situation where it can get over written. I prefer talking about threads, 
because they bring an entirely unknown element to the discussion and 
shutdown any localized assumptions.

In the case of immutable it should not be possible for immutable memory 
to be changed unless someone did something bad.

Immutable is a very strong guarantee at the process level, that there 
are no mutable pointers pointing at immutable memory.

Therefore the compiler is free to make that optimization without 
concern. If it breaks, it's the users fault for misusing the language.

"The second way is to cast data to immutable. When doing so, it is up to 
the programmer to ensure that any mutable references to the same data 
are not used to modify the data after the cast."

https://dlang.org/spec/const3.html#creating_immutable_data


More information about the Digitalmars-d mailing list