By ref and by pointer kills performance.

Iain Buclaw ibuclaw at gdcproject.org
Wed Feb 14 14:02:31 UTC 2024


On Wednesday, 14 February 2024 at 04:49:28 UTC, Walter Bright 
wrote:
>
> This isn't a case of buggy DFA. It's a case of doing DFA 
> correctly.
>
> The issue is pointer aliasing. A pointer can point to anything, 
> including const data. Therefore, storing through a pointer can 
> alter any value that is reachable via a pointer. Therefore, 
> storing through a pointer invalidates any cached value already 
> read.
>
> This is what you're seeing.
>
> C99 tried to address this with __restrict, but few people use 
> it or understand it. D didn't bother with it because people 
> will inevitably misuse __restrict and get their data 
> mysteriously corrupted.

This, here, is the answer.

Moral of the story, use (gdc, ldc) vendor attributes if you 
really care.

```
import core.attribute;

void fillBP(@restrict uint* dest, uint* value)
{
     //...
```


More information about the Digitalmars-d mailing list