I have 5 functions that get 10,000+ times (average). All of them modify / use certain variables.
I know that bad practice has global variables. But for the sake of performance, does it make sense to keep them global and not pass them - especially when I call a function call multiple times?
OR Am I not going to make a lot of money on productivity?
Do not enter global variables / global state for performance purposes. This is a mistake, contrary to all good coding rules, and usually does not help performance (it can even hurt).
If it is difficult for you to transfer many variables, you can put them in a context structand pass one pointer to struct. This way you avoid creating a global state (even staticdata retention variables are global), which prevents your code from being used in multiple instances. The cost is actually zero, and in fact it will be less expensive than global variables in position-independent code (shared libraries or position-independent executables).
struct
static
- C- , - , 1 . , .
, , , , , bss. , , , , .
, , (, ).
, , . , , ( ), , , , .
, , , , , , (, , ) . / , . , .
, , . .
. , , , , . .
, , . , .
: , .
. , , , , .
, , , , . , , , . , , , , - . - ( ) .
, . , , .
, x86. ARM , , , .
, .
8- (HT-PICC18), , / . / . . , , - .
Introl 68HC11 , , , , , . , , .
ARM, , : , . , , . , , : , .
, (.. - ). , .
, , , , , , .
. , (, , , , ) , () .
, , .
In any case, if you want to do this, you can also consider declaring all functions and variables in one file and declaring variables as static. Thus, only functions declared in the same file can access them.
See here