Efficient way to pass struct as parameter

Jonathan M Davis newsgroup.d at jmdavisprog.com
Tue Jan 2 23:14:56 UTC 2018


On Tuesday, January 02, 2018 22:49:20 Adam D. Ruppe via Digitalmars-d-learn 
wrote:
> On Tuesday, 2 January 2018 at 22:17:14 UTC, Johan Engelen wrote:
> > Pass the Vector3f by value.
>
> This is very frequently the correct answer to these questions!
> Never assume ref is faster if speed matters - it may not be.

It also makes for much cleaner code if you pretty much always pass by value
and then only start dealing with ref or auto ref when you know that you need
it - especially if you're going to need to manually overload the function on
refness.

But for better or worse, a lot of this sort of thing ultimately depends on
what the optimizer does to a particular piece of code, and that's far from
easy to predict given everything that an optimizer can do these days -
especially if you're using ldc rather than dmd.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list