A quick performance/memory question:
What is better, if there even is a difference?
This
int x;
for (int i = 0; i < 10000; i++)
{
x = i;
//do something
}
or this
for (int i = 0; i < 10000; i++)
{
int x = i;
//do something
}
?
A quick performance/memory question:
What is better, if there even is a difference?
This
int x;
for (int i = 0; i < 10000; i++)
{
x = i;
//do something
}
or this
for (int i = 0; i < 10000; i++)
{
int x = i;
//do something
}
?
I think they will both be the same in terms of assembly (its faster to just do a large stack push than a bunch of push pops for local variables sometimes). It will just reduce the scope of x in the second case even if they both produce the same bytecode.
It is exactly the same... defining a variable (primitive / reference) is just calculating the position where it will live (as an offset of the stack pointer). That is done by the compiler.