Forced array clearing in MT5? - page 3

 
Vladimir Karputov:

Failure to initialise the array is entirely the fault of the kodopistael. Look for errors in your own environment. Rebuild your algorithm.

There is no error.

The automatic array initialization with zeroes during declaration is simply disabled. Why? - unknown. Because of this you have to clear the array manually before using it. This is not always convenient.

 
Реter Konow:

There is no error.

Just removed automatic initialization of arrays with zeros during declaration. Why? - unknown. Because of this you have to clear the array manually before using it. This is not always convenient.

What do you want? Writing carelessly in the style of "4"? Recklessly query nonexistent indexes? Hope for a "man" who initializes your arrays for you?

MQL5 will strongly reprimand such amateurs, so they don't have any slack. Learn to write correctly from the beginning: if you've created an array, you must bypass all indices and fill them. If you don't want to fill them all at once - fill them step by step with preliminary increase of array's size.

In general, make a normal algorithm and do not shift your problems to others.

 
Vladimir Karputov:

What did you want to do? Writing carelessly in the style of "4"? Recklessly query non-existent indices? Rely on the "uncle" who initializes your arrays for you?

MQL5 will strongly reprimand such amateurs, so they don't have any slack. Learn to write correctly from the beginning: if you've created an array, you must bypass all indices and fill them. If you don't want to fill them all at once - fill them step by step with preliminary increase of array's size.

In general, make a normal algorithm and do not shift your problems to others.

Prefilling an array is hardly likely to cause any errors. It is convenient.

In MT5, you declare an array, clean up the trash, and then use it.

In MT4, you declare an array and use it.

That is the difference.

Why should we shift the task of clearing the arrays onto a user?

Does it increase their professionalism? Perhaps. But it certainly will not add any positive emotions)). So, sorry for my negativity. I spent several days trying to figure out what was wrong. It's getting to me.)

 
Removed auto-cleaning due to speed.
 
Реter Konow:

There is no error.

Just removed automatic initialization of arrays with zeros during declaration. Why? - unknown. Because of this you have to clear the array manually before using it. It's not always convenient.

Peter, the initialization is removed, because this procedure takes time, and in C++ and MQL5 it's not customary to pay for something you don't use. Initialization of an array is not always needed, for example, if you fill the array with the required values immediately, it's not needed.

Anyway, from your question I don't understand what the difficulty is. You always know your array's size. If you repartition an array, you always know how many more elements you are adding to it. So, it's easy to call the ArrayInitialize function right after ArrayResize.

You may ask, how do people use MQL5 when they have to additionally consider so many things? The answer is: Those who use MQL5 on a good level use the standard library, so they don't even think about all this stuff, they don't initialize an array or relabel it, they just add new values. But since you're a dartan and don't recognize any of this, you have only one option: low-level, painstaking management of your arrays, using ArrayInitialize.

 
Vasiliy Sokolov:

1. Peter, initialization is removed, because this procedure takes time, and in C++ and MQL5 it is not customary to pay for something you don't use. Array initialization is not always needed, for example if you fill the array with required values immediately, it is not needed.

And still from your question I don't understand what the difficulty is. You always know the size of your array. If you repartition an array, you always know how many additional items you are adding to it. So it's easy to call the ArrayInitialize function after ArrayResize.

You may ask, how do people use MQL5 when there are so many additional things to consider? The answer is: Those who use MQL5 on a good level use the standard library, so they don't even think about these things, they don't initialize an array or its repartitioning, they just add new values. But since you're a dartan and won't admit anything of the kind, you have only one option: low-level, painstaking management of your arrays, using ArrayInitialize.

Vasily, point by point:

1. Logic tells us that the array cleanup procedure is executed by the compiler only once at the compilation stage. If it was removed, it means that we wanted to increase the compiler's performance to the detriment of the programmer's convenience but perhaps to increase his level.

2. The size of the kernel depends on the cyber code. The more items, the bigger the kernel array. Therefore, the kernel is dynamic. It is built in stages. If there is trash in its cells, the references of one cell to another in functions at different stages of building will cause program crash.

In MT4 there was no such a problem because uninitialized cells were zeros and not random values. In short, my technology should work initially with a clean array.

3. I'm not against forced custom array clearing, just, like I said, got a bit of a nag. For a few days I couldn't understand why everything crashes. Thought it was my fault, it turned out - they've taken away one of my conveniences)).


Never mind, we'll get used to it.)


ZS. By the way, I should say my code is absolutely crossplatform. I don't need to change anything except this cleanup!

 
Реter Konow:

There is no error.

Just removed automatic initialization of arrays with zeros during declaration. Why? - unknown. ...

So that we could write fast programs. Initialization is far not always needed, more often the array is filled with its own data right away.

 
Dmitry Fedoseev:

In order to be able to write fast programs. Initialisation is not always necessary, the array is often filled with its own data immediately.

OK. I see.

 
Реter Konow:

... If there is rubbish in its cells, then references of one cell to another in functions at different stages of construction, cause the program to crash.

Piotr, if you have rubbish in your kernel, you alone are responsible for it. MQL5, unlike MQL4, does not try to understand what the user wants and this is correct.

 
P.S. I think you'd have been much luckier, Peter, if you'd have ended up in a JavaScript forum of some sort. There's a lot of those delights there. You'd have reached great heights!
Reason: