title: Passing many variables vs. passing struct
body: <p>When passing several pointers to a function, in terms of performance only:
  is is better to pass a pointer to a struct with all the pointers inside and then do something like code 1 or passing the pointers to variables directly?</p>
  
  <p>I think that for small number of variables, the option two outperforms option 1 for sure, but is that the case when we have, say, 100 variables?</p>
  
  <p>I found some questions about this, but none very conclusive in terms of performance only.</p>
  
  <p><a href="https://stackoverflow.com/questions/28041181/what-is-better-practise-in-high-performance-computing-passing-a-struct-of-data">What is better practise in high-performance computing: passing a struct of data into a function or a set of variables?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/38207395/efficiency-of-passing-a-struct-to-a-function-without-instantiating-a-local-varia">Efficiency of passing a struct to a function without instantiating a local variable</a></p>
  
  <p><a href="https://stackoverflow.com/questions/2297897/declaring-passing-structs-vs-declaring-passing-individual-values/13590535#13590535">Declaring/passing structs vs. declaring/passing individual values</a></p>
  
  <p>OPTION 1</p>
  
  <pre><code>void myFunctionOne(void *pointerToStruct){
      struct myTypeOfStruct *localPointerToStruct;
      localPointerToStruct = (struct myTypeOfStruct *)pointerToStruct;
  
      for(i=0;i&lt;n;++i){
          *(localPointerToStruct-&gt;a+i) = sth;
          *(localPointerToStruct-&gt;b+i) = sthElse;
          ...
          *(localPointerToStruct-&gt;z+i) = sthElsez;
      }
  }
  </code></pre>
  
  <p>OPTION 2</p>
  
  <pre><code>void myFunctionOne(double *a, double *b,...,double *z){
      for(i=0;i&lt;n;++i){
          *(a+i) = sth;
          *(b+i) = sthElse;
          ...
          *(z+i) = sthElsex;
      }
  }
  </code></pre>
  
  <p>OPTION 3</p>
  
  <p>A third option that might seem a bit weird would be doing the first case but instead of iterating over the pointers inside the struct, copy them to local pointer variables.</p>
  
  <pre><code>void myFunctionOne(void *pointerToStruct){
      struct myTypeOfStruct *localPointerToStruct;
      localPointerToStruct = (struct myTypeOfStruct *)pointerToStruct;
  
          double *a = localPointerToStruct-&gt;a;
          double *b = localPointerToStruct-&gt;b;
          ...
          double *z = localPointerToStruct-&gt;z;
  
      for(i=0;i&lt;n;++i){
          *(a+i) = sth;
          *(b+i) = sthElse;
          ...
          *(z+i) = sthElsex;
      }
  }
  </code></pre>