declaring doubles

 
perhaps someone here with better understanding can help me decide.... my delima is , where to declare double's and int's, variables, when large numbers of variables will be declared in the ea....

let me explain..... i have the exact same ea written with variables declared in a group at the top of each section and i have the exact same ea written with all variables declared in the line they first appear....


now if only a few variables are used surely it should not matter..... but when a hundred or more are being used it might in some way increase the work for the computer, or so i've been told.....

it's far simplier for me to declare variables at their first point of mention.....and it's a real pain trying to declare them all at the top..... now i'm only talking about when hundreds of variables are being used.....

i've timed backtests on that ea written in both methods and it does not appear to be slower using either method....


does someone know if there is any real advantage to declare variables in a group at the top..... the computers i'm using are the fast dual cpu's with memory to spare so there should not be an issue with them....... thanks for any input......h
 
Variables declared "at the top", before the start() function, are visible to all code inside the start() function, as well as available to any functions defined in the same file, including init() and deinit(). They are intialized one time, before start() begins. If your variable is to be accessed by many parts of the code, declaring at the top is necessary.

Variables declared inside the start() are not be visible to functions outside of start(), such as functions you write as well as init() and deinit().

Variables declared inside loops are local to the loop code.

If you want "one time" initialization inside the body of your code, declare the variable as static. You can still assign values to the variable as you go, but it is declared and initialized only at the first occurrence.

As far as performance issues, as you saw, it generally makes no discernable difference.

Let's estimate performance: If it takes 500 clock cycles to initialize a variable and you have a 2ghz clock, you can initialize 4,000,000 variables per second. 500 clock cycles to init a variable is probably a wildly pessimistic estimate.
Still, that is 4000 variable inits per millisecond. How many do you need?
 
hey phy...... thanks for the reply.... your thoughts parallel mine but someone mentioned to me my method of coding would create undo strain on the cpu......

it's just so much simplier to code and easier to read when each variable is declared at first mention, similar to this....

//----------------------------

double dayfour = iMA(NULL, 1440, 4, 0, 0, 0, 1);
double daysix = iMA(NULL, 1440, 6, 0, 0, 0, 1);
double dayten = iMA(NULL, 1440, 10, 0, 0, 0, 1);
double daytwelve = iMA(NULL, 1440, 12, 0, 0, 0, 1);
double dayfourteen = iMA(NULL, 1440, 14, 0, 0, 0, 1);

//---------------------------

thanks again for your reply.....h