Reputation: 483
I've clubbed all the variable members from the main function and created a few structures to make it organised and less complicated. My issue is instead of passing the particular parameters for the respective function like before, I'm now passing the entire structure with huge array sizes into each function. I want to know whether it affects performance and if so a better way to do it.
const int ard = 4096;
const int are = 8192;
const int ars = 64;
struct DataStructure_init {
int main_seq[are][24];
int main_seq2[are][24];
int main_seq3[are][24];
int main_lim[arc];
int cou[ars][16];
int gx[ars][32];
int sx[ars][32];
int col[ars];
int sol[ars];
int mix[ars];
int max[ars];
int hig[ars];
int save[are];
int list[are];
int lis[are];
int li;
int mark;
int fth[16];
...
};
struct DataStructure_trus {
...
};
DataStructure_trus va;
DataStructure_init in;
int fpre (DataStructure_trus va,DataStructure_init& in);
int ftrus (DataStructure_trus& va);
int fseries(DataStructure_trus& va);
int ftcs (DataStructure_trus va,DataStructure_init& in);
int finit (DataStructure_trus va,DataStructure_init& in);
int fith (DataStructure_trus va,DataStructure_init& in);
int flist (DataStructure_trus va,DataStructure_init& in);
int fope (DataStructure_trus va,DataStructure_init& in);
int fggs (DataStructure_trus va,DataStructure_init& in);
int fpow (DataStructure_trus va,DataStructure_init& in);
int fbin (DataStructure_trus va,DataStructure_init& in);
Upvotes: 0
Views: 454
Reputation: 143279
Passing big structures by value definitely impacts performance severely. Though passing by reference probably makes the impact negligible.
Also, passing big structures by value can make you think of this site name.
Upvotes: 5
Reputation: 34664
Passing by reference will, as Michael said, have little performance implications. However there are also arguments that indicate that passing the struct not as reference will actually be faster. However, it is not clear when this will actually be true, so it will come down to profiling. Try both approaches and let a profiler run over it, or simply run the program and measure the time it takes.
Upvotes: 1