`in` parameters made useful
Mathias LANG
geod24 at gmail.com
Tue Aug 25 16:05:51 UTC 2020
On Tuesday, 25 August 2020 at 12:09:45 UTC, Kagamin wrote:
>
> 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.
I assume you imply that it's less optimal because it's taking the
address of it ?
> If a non-POD object is passed by value, it will have extra
> calls to postblit and destructor.
https://github.com/dlang/dmd/blob/master/changelog/preview-in.dd
> - If the type has an elaborate copy or destruction (postblit,
> copy constructor, destructor),
> the type is always passed by reference.
More information about the Digitalmars-d
mailing list