rvalue references

kink via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 9 07:53:48 PDT 2015


On Tuesday, 9 June 2015 at 13:13:53 UTC, Steven Schveighoffer 
wrote:
> It's actually faster to pass an rvalue by value, because it's 
> constructed on the stack anyway.

I seriously doubt that's true for a large struct, e.g., something 
containing a large static array. Why move/copy the damn thing if 
I'm only going to read a tiny portion of it?

And please don't forget the ABI in that regard. E.g., on Win64, 
only POD types <= 64 bits (and whose size is a power of 2) are 
really passed by value (in a register or on the stack); all other 
types are passed as reference to a dedicated copy allocated on 
the caller's stack. So in this case, the indirection is enforced 
by the ABI anyway. If the callee is not going to modify the 
parameter, the copy should obviously be elided, falling back to 
classical byref passing.


More information about the Digitalmars-d mailing list