|Global versus Stack variables email@example.com (shrey) (2005-11-19)|
|Re: Global versus Stack variables firstname.lastname@example.org (email@example.com) (2005-11-21)|
|Re: Global versus Stack variables firstname.lastname@example.org (glen herrmannsfeldt) (2005-11-21)|
|Re: Global versus Stack variables email@example.com (2005-11-21)|
|Re: Global versus Stack variables firstname.lastname@example.org (2005-11-21)|
|Re: Global versus Stack variables email@example.com (Jatin Bhateja) (2005-11-26)|
|Re: Global versus Stack variables firstname.lastname@example.org (2005-11-26)|
|Re: Global versus Stack variables email@example.com (Dave Thompson) (2005-12-05)|
|Date:||21 Nov 2005 22:40:47 -0500|
|Keywords:||storage, optimize, comment|
|Posted-Date:||21 Nov 2005 22:40:47 EST|
> Hi all
> I was wondering if ppl can give their opinion on the following
There are a number of factors that effect the performance of locals and
* if you are targetting an architecture with enough registers (eg.
not an x86) it becomes possible to keep many locals inside registers,
and reduce the number of memory accesses, etc.
* Dependency and data flow analysis is more practical with local
variables as the compiler doesn't need to worry about the contained
values changing between function calls (same holds for concurrent
modification of variables). C bypasses these problems by assuming
everything is is effectively local (during dependency, etc analysis)
unless a var is declared volatile.
* It may be possible to read a fixed address global faster than a
local depending on architecture, but i would imagine the cache in most
architectures would destroy that advantage nowadays.
There are other things that effect performance, but the first two alone
should give locals a reasonable performance advantage (in my opinion
anyway :) )
> [It depends on your language, but in languages with pointers, the
> biggest advantage of stack locals is that the compiler can assume
> no aliasing of stack variables that haven't had their address taken.
but they shouldn't in the happy world of C anything is possible :)
int b, c;
for(int i=0; i<=10; i++) b[i]=4;
if(c==4) //a good optimizer should probably
Although yes, things like that are *probably* an error (and exceedingly
dependant on the order of vars on the stack) :)
[Things like that are definitely an error if your program purports to be
in ANSI C. -John]
Return to the
Search the comp.compilers archives again.