About ref used for performance reasons with struct
Ali Çehreli
acehreli at yahoo.com
Mon Feb 11 16:54:43 PST 2013
On 02/11/2013 04:31 PM, jerro wrote:
>> To be honest, up until recently, I mistakenly thought the compiler DID
>> do this. (Yea, my mistake.)
>>
>> Is it possible I had confused structs with static arrays? Do static
>> arrays do that?
>
> Maybe you were thinking about named return value optimization (which
> applies to return values, not parameters)?
There is a corresponding optimization for parameters, which can be
applied only in some cases.
The related guideline in C++ is this: If you are going to make a copy of
the parameter inside the function anyway, take the parameter by-value.
Here is a related article:
http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/
Especially this part: "Also, although the compiler is normally required
to make a copy when a function parameter is passed by value (so
modifications to the parameter inside the function can’t affect the
caller), it is allowed to elide the copy, and simply use the source
object itself, when the source is an rvalue."
Ali
More information about the Digitalmars-d
mailing list