Simplest way to make dynamic array 2nd dimension indexes all to zero without a loop?

 

I have searched and tried to figure it out for a couple weeks without making a loop and setting each index to zero individually.

Is there a simple way to just clear all the indexes in the 2nd dimension? seems like Arrayinitialize() only clears the first dimension. Thanks.

 

hello,

i can not directly answer your question, but what is the problem with having a loop? You can also put it in a function to use it easily; if your concern is about speed, i am almost sure, a loop can be as fast in mql code as in assembly (so, it should not matter if you use a ready-made function, or one you are writing your self, speed should be about the same ). But in any way, I assume you do not have to zero your array that frequently so a super speedy function could be even less of a concern :)

best regarsd 

 
c3po:

I have searched and tried to figure it out for a couple weeks without making a loop and setting each index to zero individually.

Is there a simple way to just clear all the indexes in the 2nd dimension? seems like Arrayinitialize() only clears the first dimension. Thanks.

Just in case that there were a solution for our problem like ArrayMultiDimIni() I guess that this function would lop through all the indices and it might be slower than your way knowing the dimension as this function first has to find out first how many dimension does have the array and what are their sizes.
 
template <typename Datatype>
void ArrayMultiDimIni(Datatype& a[][], Datatype value){
   int iFirst = ArrayRange(a, 0);
   int iSecond = ArrayRange(a, 1);
   while(iFirst > 0){
      --iFirst;
      for(int iEnd = iSecond; iEnd > 0;) a[iFirst, --iEnd] = value;
}  }
 
WHRoeder:
template <typename Datatype>
void ArrayMultiDimIni(Datatype& a[][], Datatype value){...}

Hi WHR,

how do you call that technique of datatyping ? Is there any info about at MQ4-Ref ?

Thanks 

Reason: