Forced array clearing in MT5?

 

I've never seriously worked with MT5, and now I'm transferring a huge project to it at once. Naturally, there are difficulties, one of which is constantly going outside the array. MT4 didn't have such a problem, as it turns out, also because arrays didn't need to be purposely cleared after the announcement. But in MT5 it is necessary. My technology requires gradual filling of the kernel along with changes of its size. The exact size of some arrays is not known in advance. At the same time, because of the great number of loops on arrays in the process of their filling, everything would be out of order. If there were no rubbish in the cells, everything would have worked long ago.

That is, there's rubbish in arrays on one hand and critical error of overruns on the other hand. It's like a draconian condition...

I want to understand why they had to remove automatic clearing of arrays and reduce declared variables to zero, like in MT4?

If we can tolerate variables, we will have to face the problem of constant rubbish collection in large arrays, and we will have to clean them up not only when declaring, but also when resizing... Why?

 

The reason for going out of bounds is that arrays are filled with values gradually in different functions, and in this process, one cell is accessed via another cell. Some functions are called twice and fill the array sequentially. But, if there is rubbish in the cells, there is an overrun on the first fill.

The problem could probably be solved by clearing the arrays in advance, but of course this is an additional headache. Pity.

 
OK, let's not complain. )) It just takes some getting used to. ))
 

Get used to it.

I always declare an array, set the expected size, fill it with values (initialize it). It's often better to initialize with a non-zero value - it's easier to find an error that way.

 
Peter, I don't know what you mean?
There is a dynamic array, there is the current size of this array, there is an overflow control.
Personally, I try to avoid overflow control, and use it only at design stage, because if the algorithm is correct without errors, overflows don't occur. Why do you need unnecessary checks?
If you have an overflow occurring, look for errors. A debugger with interrupt points helps you or without interrupt points, because the program stops in debug mode when an overflow occurs and you can look at the variables.
And if there's rubbish, it's your rubbish that you haven't cleaned up.
 
Реter Konow:

I've never seriously worked with MT5, and now I'm transferring a huge project to it at once. Naturally, there are difficulties, one of which is constantly going outside the array. MT4 didn't have such a problem, as it turns out, also because arrays didn't need to be purposely cleared after the announcement. But in MT5 it is necessary. My technology requires gradual filling of the kernel along with changes of its size. The exact size of some arrays is not known in advance. At the same time, because of the great number of loops on arrays in the process of their filling, everything would be out of order. If there were no rubbish in the cells, everything would have worked long ago.

That is, there's rubbish in arrays on one hand and critical error of overruns on the other hand. It's like a draconian condition...

I want to understand why they had to remove automatic clearing of arrays and reduce declared variables to zero, like in MT4?

If we can tolerate variables, we will have to face the problem of constant rubbish collection in large arrays, and we will have to clean them up not only when declaring, but also when resizing... Why?

Also encountered similar difficulties at first.

In my opinion, arrays are filled in a specific way, this should be taken into account in loops often.

 
Nikolai Semko:
Peter, I don't know what you mean?

all about the samehttps://www.mql5.com/ru/forum/293630/page179#comment_10802823

now it's MQL5's fault... ;)

Мой подход. Ядро - Движок.
Мой подход. Ядро - Движок.
  • 2019.02.28
  • www.mql5.com
В этой ветке, я хочу рассказать о своем подходе в программировании. Заранее предупреждаю, - здесь не будет обсуждений GUI...
 
Igor Makanu:

all about the samehttps://www.mql5.com/ru/forum/293630/page179#comment_10802823

now it's MQL5's fault... ;)

Right. I'm not used to MQL4.
What, really, no need to control overflows there? But it's terrible, isn't it? How do you catch errors?
 
Nikolai Semko:
Yeah. I'm not used to MQL4.
What, really, there's no need to control overflows? But that's terrible, isn't it? How do I catch errors?

Nikolay, do not worry about MQL4, everything is fine there. The topic-starter fills the arrays as he likes. That's it.

 
Nikolai Semko:
Well, yes. I'm not used to MQL4.
What, really, there's no need to control overflows? But that's terrible, isn't it? How do you catch errors?

Of course you do.

Any programmer who respects himself and his programs will not let things slip. In MQL4, if you don't use #property strict, you can refer to an array with size 10 by index 20. And nothing will happen - the program will continue to work, but it is up to the programmer to decide what to use next. If he is smart, he will certainly check and control everything, so as not to get values outside the array, but if he does it "with a bang", he does not care about this control, and "the main thing is that it works, but how it will work somehow...".
The majority of users, who haven't bothered with this, have been complaining about "bad, evil and complicated MQL5", because it does not allow them to fake their own creations as before. But those who originally thought and created code with checking and controlling received data, didn't notice any difference in complexity of languages, and now wonder - "where's the complexity - it's the same...".

 
Реter Konow:

I've never seriously worked with MT5, and now I'm transferring a huge project to it at once.

Serious difference in arrays when rewriting

Forum on trading, automated trading systems and trading strategies testing

Features of mql4 language, subtleties and tricks

fxsaber, 2019.02.12 13:12

Features of ArrayResize for multidimensional arrays
void OnStart()
{
  int Array[][2];
  
  Print(ArrayResize(Array, 7)); // MQL5 - 7, MQL4 - 14
  Print(ArraySize(Array));      // 14
}
Reason: