nil_dib
asked on
memory question
Is there a difference between:
MyFunc()
{
if(...)
return;
int i;
....
}
and:
MyFunc()
{
int i;
if(...)
return;
....
}
concerning the stack/memory ??
MyFunc()
{
if(...)
return;
int i;
....
}
and:
MyFunc()
{
int i;
if(...)
return;
....
}
concerning the stack/memory ??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
MyFunc()
{
{
int i;
}
}
would actually set up and destroy a second stack frame in some cases. There is no telling how such a compiler would handle the case you presented.
I think you can be sure of this. There is goign to be no significant difference in execution speed between the two. This is because operations required to provide space for the integer are insignificant. This would not be true if the variable in question had a constructor that took considerable time to run, for example, if the constructor read from a file. In that case, the first version would be faster.
You have this quesions 2 times. You might want to delete the other.