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

Back to topics list To post a new topic, please log in or register
avatar
43
c3po 2015.11.24 13:50
 

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.


avatar
126
Demos 2015.11.24 17:52 #
 

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 

avatar
2017
gooly 2015.11.24 18:14 #
 
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.
avatar
12983
WHRoeder 2015.11.24 18:56 #
 
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;
}  }

avatar
23
GoS 2015.11.24 19:10 #
 
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 

avatar
12983
Back to topics list  

To add comments, please log in or register