Taking arguments by value or by reference

Anonymouse zorael at gmail.com
Sat Oct 3 23:00:46 UTC 2020


I'm passing structs around (collections of strings) whose .sizeof 
returns 432.

The readme for 2.094.0 includes the following:

> This release reworks the meaning of in to properly support all 
> those use cases. in parameters will now be passed by reference 
> when optimal, [...]
>
> * Otherwise, if the type's size requires it, it will be passed 
> by reference.
> Currently, types which are over twice the machine word size 
> will be passed by
> reference, however this is controlled by the backend and can be 
> changed based
> on the platform's ABI.

However, I asked in #d a while ago and was told to always pass by 
value until it breaks, and only then resort to ref.

> [18:32:16] <zorael> at what point should I start passing my 
> structs by ref rather than by value? some are nested in others, 
> so sizeofs range between 120 and 620UL
> [18:33:43] <Herringway> when you start getting stack overflows
> [18:39:09] <zorael> so if I don't need ref for the references, 
> there's no inherent merit to it unless I get in trouble without 
> it?
> [18:39:20] <Herringway> pretty much
> [18:40:16] <Herringway> in many cases the copying is merely 
> theoretical and doesn't actually happen when optimized

I've so far just been using const parameters. What should I be 
using?


More information about the Digitalmars-d-learn mailing list