About ref used for performance reasons with struct

Dan dbdavidson at yahoo.com
Tue Feb 12 10:11:04 PST 2013


On Tuesday, 12 February 2013 at 17:33:08 UTC, deadalnix wrote:
> This is a lot o code

Fortunately, like a lot of code you don't need to look at it to 
use it. That is the purpose of it.

   struct ReductionMap(K, V, alias reduction_op = "+", alias init 
= 0) {
     mixin ReadOnly!_dataMap;
     mixin ReadOnly!_reduction;
     alias V[K] DataMap;
     ...
     private {
       DataMap _dataMap;
       V _reduction = init;
     }
   }


> and don't handle some cases. For instance
>

I did not say it handled everything and if you have strategies 
that will allow me to simply, declaratively get a better 
selection between the two pass types I'd incorporate it. If and 
until the language changes, what other choices are there?

I just used the numbers to come up with a heuristic, which I 
imagine, given the state of things is how any one makes the 
choice. The only difference is the choice is somewhat formalized.


> struct A {
>     long a;
>     double b;
> }
>
> is generally better passed by ref, where
>
> struct A {
>     long a;
>     long b;
> }
>
> is better passed by value.

Any performance numbers?

Even if that were true, is it realistic to expect a compiler to 
get it right each time?

Thanks
Dan



More information about the Digitalmars-d mailing list