About ref used for performance reasons with struct

Michel Fortin michel.fortin at michelf.ca
Mon Feb 11 07:48:32 PST 2013


On 2013-02-11 06:52:28 +0000, "deadalnix" <deadalnix at gmail.com> said:

> When a function accept a struct, the compiler is free to use that 
> function, or an altered one taking a reference as parameter.

When designing the ABI, you can either create the copy on the caller's 
side, or the callee's side. If I'm understanding well, you want to have 
two versions of each function, one copying on the caller's side, one 
copying on the callee's side, and the caller's codegen would choose 
which one to use. Copying on the caller's side is better if you're 
passing rvalues (because the caller can just always skip the copying), 
while copying on the callee's side is better when you're passing 
lvalues, because the caller may decide to skip copying if it doesn't 
need a copy.

I'm not sure creating two versions of each function will fly well with 
Walter. Actually, you say *two* are needed, but that's for a function 
with one struct parameter; it's more 2^(number of structs parameters) 
versions you'd need in the general case.


-- 
Michel Fortin
michel.fortin at michelf.ca
http://michelf.ca/



More information about the Digitalmars-d mailing list