Mail Archives: djgpp/1998/06/14/02:33:45
Nate Eldredge wrote in message <35833ED8 DOT 9EB75F08 AT cartsys DOT com>...
>> Quick question: is access to a dynamically allocated array slower than a
>> static global array, or are they the same?
>
>They're the same. Memory is memory. Of course, if it gets swapped out,
>it will be slower, but that can apply in either case.
Here was my logic: static variables/arrays can only be accessed by the
source file that they are declared in, so I figured that they would be
closer to the functions they were used in on the stack. A global
variable/array can be accessed by any source file/function that uses it, so
accesses to it are further along on the stack, and this access takes longer.
So in my application (a NES emulator) any array or variable that needs to be
shared between functions, I try to declare as static so that it can be
accessed by the functions in that source file, but not functions from other
linked object files.
Is there a flaw in my logic?
All replies (posts) are appreciated, as I've never found conclusive answers
to this topic.
Thanks,
Matt.
- Raw text -