Discussion: Rvalue refs and a Move construtor for D
kinke
kinke at gmx.net
Thu Aug 29 12:16:45 UTC 2019
On Thursday, 29 August 2019 at 08:58:55 UTC, RazvanN wrote:
> https://github.com/RazvanN7/DIPs/blob/Move_Constructor/DIPs/DIP1xxx-rn.md
> Currently, the DMD compiler does not perform any move operations
It does, the classical example being passing an rvalue argument
by value to the callee:
struct S
{
long[32] data;
this(this) {}
~this() {}
}
void callee(S s) {}
void caller() { callee(S()); }
It allocates a first S instance on the caller stack and then
moves that into a 2nd instance on the callee params stack
(current D ABI on Posix x86_64 - non-PODs passed by value are
passed on the stack), blitting the 32*8 bytes but eliding
postblit (and destruction of the 1st instance) and letting callee
destruct the moved-into 2nd instance.
C++ passes a ref under the hood in such a case and can thus
simply pass a pointer to the first instance, no blitting
happening at all.
More information about the Digitalmars-d
mailing list