calling convention optimisation & const/immutable ref

Johan Engelen via Digitalmars-d digitalmars-d at puremagic.com
Tue Nov 8 04:56:10 PST 2016


On Monday, 7 November 2016 at 16:48:55 UTC, John Colvin wrote:
> Some people use ref for performance to prevent the copying that 
> must occur when passing by value.

This reminds me of an LLVM presentation by Chandler, mentioning 
that passing by reference may hamper the optimization of code 
(because memory becomes involved). I don't think he gave a clear 
example, but one thing I can think of is potential aliasing:
void foo(ref LargeThing a, ref LargeThing b), where a and b may 
alias partly.
To do the "ref" optimization for _all_ large function parameters 
per default sounds like a bad idea.

Also, how would I turn the optimization off (I guess extern(C++) 
would do that?)? What if my function needs a local copy (say, in 
multithreaded stuff), and I want that copy to be const?

-Johan



More information about the Digitalmars-d mailing list