`in` parameters made useful

Kagamin spam at here.lot
Tue Aug 25 12:09:45 UTC 2020

On Friday, 21 August 2020 at 18:23:08 UTC, Mathias LANG wrote:
> The second example is pretty simple: the backend will decide 
> whether to pass it by ref or not. Since it's a small type, it 
> might make more sense to pass it in registers. Whether or not 
> it's ref does not matter to the programmer, because the 
> programmer cannot change the input anyway, only read it.

The backend doesn't know how to load the data. It matters to the 
programmer, because it affects performance.

Another example:
void log(in ref int n)
   write(fd, &n, n.sizeof);
If the argument here is passed by value, it will need to fiddle 
with stack and the code will be less optimal.

>> Doesn't this defeat your optimization when passing by value is 
>> expensive?
> I don't see how ?

If a non-POD object is passed by value, it will have extra calls 
to postblit and destructor.

More information about the Digitalmars-d mailing list