nadom7, yeah, it might be just a latency issue, though. Perhaps the program access local data quite a lot, but the global and static data that must stored in a different page it doesn't. In some situations, not using globals could be faster, but if you'll passing a lot of data round as parameters using globals could be faster. But I wouldn't worry too much about it. I'd just go for clarity first.Quote:
I believe I understand most of the negative impact that global variables have on a program. One major issue is their negative effect on your program's performance.
Another issue with globals, I think, is a compiler that doesn't optimize outside of functions will have trouble optimizing somtimes. For example, say you have
Then, for such a compiler, it'll compile code to have to load globalVar into a register in f() before the call to g() but unless if the compiler can detect that g() doesn't modify globalVar, it'll likely have to reload globalVar into a register.Code:
int c = 0;
c = globalVar + 5;
printf("c = %d\n", globalVar);
printf("global var = %d\n", globalVar);
Ancient Dragon, Pentium 4 has registers that are not visible to the assembly programmer. These latter pentiums are also RISC, and they, as I've been told, translate the very complex instructions into simple instructions that likely use hidden registers. They also have registers for floating point, operating system control, paging, MMX, etc so the number of registers in the latter processers has gone up quite a lot.Quote:
Function algorithms are even more important in your program than I originally mentioned. If you are running the program on a PC such as Pentium, it still won't make much difference because of the CPUs very limited number of registers (there are only 4 general-purpose registers, eax ebx ecx and edx.