On Mon, 24 Jul 2006 15:00:04 +0200, jacob navia
In some processors
(1)
int fn(void)
{
char buf[2024];
int counter;
}
will make a performance difference with
(2)
int fn(void)
{
int counter;
char buf[2024];
}
If the stack variable "counter" is in the stack and is used a lot,
each access will use a shorter instruction in case (2), since
the offset from the frame-pointer is less than 128 bytes and
can use shorter instructions.
Unless the compiler is halfdecent (most are nowadays) and the
processor is also (x86 isn't) then it will keep counter in a register
and not in the stack at all. <pedantic> Assuming of course there is a
single stack and automatic variables are (normally) in it, which are
common but not required and not universal. </>
And not on Tandem NonStop where the first will (naively) use
counter L+1
buf L+2,S or L+3,S or L+2,X or L+3,X depending on modes
and the latter will use
buf L+1,S or L+1,X depending on modes
counter L+2 or L+3 depending on modes
and the code generated will do exactly the same number of virtual
accesses either way; physical performance may be affected by cache
differences, but that could go either way depending on a large variety
of factors that can't practically be predicted or probably even
measured, and similarly on many (most?) other platforms.
Although there are _other_ cases where ordering of declarations would
make a difference on TNS, some of which would make _no_ difference on
the platforms/implementations you are familiar with.
This could make 0.000001% of efficiency gain in some processors.
This supposes a compiler that does NOT optimize this by
making stack layout independent from declaration order!
or use registers, as above.
Short answer:
Do not worry about this kind of details.
Agree there.
- David.Thompson1 at worldnet.att.net