Link to home
Start Free TrialLog in
Avatar of nil_dib
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 ??
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

I would have to dissagree somewhat.  To the best of my knowledge that is entirely implimentation defined.  That is, it is up to the designer of the compiler.    In fact, I believe (again I'm not sure) that it is common practice in many implimentations to set up multiple stack frames  in a function that has nested scrope, thus a function like

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.