[code here] -- calls func2 near end or at a if-then sequence
r-ID wrote:you do not need to write a function if you use it once in the code.
functions are for avoiding same code writing over and over again.
Once same code repeats write a function
r-ID wrote:1) every time you call a function variables are initialized
2) you have to declarate additional variables, such as counters, you can't reuse same variables.
3) functions are slow, everytime you call a function there are: address pushing, variables creation, jump to the function, result writing, poping variables, pop'ing memory address and jumping back to the code.
the main reason why functions or so called procedures was born is to allow to use same code twice.
and, yes, it might save some memory during the execution process.
-- Mon Sep 28, 2009 1:20 pm --
but to do that just to save memory? what kind of programs do you write, and what language? php i guess
Extra memory for variables has to be requested from the CPU, yes, but that's better than assigning memory globally - that's how memory leaks begin to occur.
Users browsing this forum: No registered users and 0 guests