[DGD] A trivial query about the behaviour of local variables

Robert Forshaw iouswuoibev at hotmail.com
Fri Apr 23 14:43:22 CEST 2004


Someone who knows the DGD code well should be able to answer this. I'm 
merely curious more than anything else.

void pointless() {
    int i;
}


I understand from the above code that the data stored in variable i is gone 
for good once the function has finished. What I would like to know is 
whether the memory space which was used for the variable i will remain 
allocated for any length of time after the function ends, to be re-used for 
the same variable if the function is called again. To me this would seem 
more efficient than simply allocating memory for the local variables at the 
start of the function and deallocating it at the end.

In other words, which of the following is true?:

void pointless() {
    int i; /* Allocate some memory to hold i */
} /* De-allocate the memory */

void pointless() {
    int i; /* Allocate some memory to hold i if the function is called for 
the first time, or hasn't
            * been called recently.
}

_________________________________________________________________
Sign-up for a FREE BT Broadband connection today! 
http://www.msn.co.uk/specials/btbroadband

_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list