I really hope this isn't one of those super basic questions.
Anyway, I've got a struct with 47 components, and I'm calling various functions that use anywhere from 3 to 10 of these components at once.
Is it better to call the function like: foo(pParam->variable1, pParam->variable2, pParam->variable3)
or foo(pParam)
and then in the function use pParam->variable1; pParam->variable2; pParam->variable3;
?
Thanks in advance!
You should pass the struct by reference, that way you don't need to copy all the values:
void foo(mySturct pParam); //Here the struct will be copy constructed.. relatively large overhead
void foo(Val1 param1, Val2 param2, Val3 param3); // 3 parameters passed by value, the value will be copied.
void foo(mySturct &pParam); //Only the reference to the structure is passed. Single pointer size value is passed.
In general structures are there so you can unite data. So it doesn't make sense to take it apart and pass different parameters to functions.
It should stay as a single unit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With