Taking arguments by value or by reference

Adam D. Ruppe destructionator at gmail.com
Sun Oct 4 20:26:16 UTC 2020


On Sunday, 4 October 2020 at 15:30:48 UTC, IGotD- wrote:
> I don't agree with this, especially if the struct is 432 bytes. 
> It takes time and memory to copy such structure.

If the compiler chooses to inline the function (which happens 
quite frequently with optimizations turned on), no copy takes 
place regardless of how you write it if the compiler can see it 
is unnecessary.

Returning a struct by value rarely means a copy either since the 
compiler actually passed a pointer to where it wants it up front, 
so it is constructed in-place.

So like "pass by value" in the language is not necessarily big 
copies in the generated binary. That's why the irc folks were 
advising to not worry about it unless you see a problem coming up 
that the profiles points here.


More information about the Digitalmars-d-learn mailing list