You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I haven't got anything backwards. I'm not the author of the piece linked to at stackoverflow.com.
What I am saying is the following:
I have nowhere said that MQL4 initialises local or member variables when #property strict is defined. I am saying that MQL4/5 is not C++, and could [choose|have chosen] to diverge from the C++ standard in this area.
I know from painful experience that (at least) the class members are not initialized in MT4.
I know from painful experience that (at least) the class members are not initialized in MT4.
From my experience most coders initialise variables and members immediately after their declaration, regardless of the programming language specification. It is cheap, and resistant to future specification changes.
Hello everyone,
I am thinking of starting my next indiClass.mqh. Something to do this (Code not completed yet).
Hello everyone,
I am thinking of starting my next indiClass.mqh. Something to do this (Code not completed yet).
Perhaps you should start the lessons on how functions work first...
I haven't got anything backwards. I'm not the author of the piece linked to at stackoverflow.com.
What I am saying is the following:
I have nowhere said that MQL4 initialises local or member variables when #property strict is defined. I am saying that MQL4/5 is not C++, and could [choose|have chosen] to diverge from the C++ standard in this area.
You are right and I would not rely on any initialization in MT4 either, as similarly to MT5, the documentation specify that variables (without differentiation) are NOT initialized implicitely.
As I already said, if someone already knows C++ that's fine, if he starts programming there is no need to learn C/C++ at all. Though he can do it if he wants of course.
Because the computer assigns it to a memory address that could have garbage in it, but in this case you improperly defined the constructor by adding "void" as it's return type. Contructors do not have a return. In order to avoid these issues make sure your constructor doesn't have a return type and it's also more efficient to initialize your member variables with an initialization list.
Don't let it overwhelm you... start out making simple classes that print to the log - and then as you learn you can start applying inheritance to make them more robust.
Could you explain, in simple words please, how using inheritance is making a class more robust ? Thanks.
More efficient ? Could you explain that please, I always thought it was just a "coding-style" without any real impact.
Could you explain, in simple words please, how using inheritance is making a class more robust ? Thanks.
Robust is used in this context as a metaphor and not it's literal translation, and it is more efficient to directly initialize a variable instead of first initializing it and then later assigning it a value.
This assigns value after initialization.
This assigns value during initialization.
...and of course you would need to initialize const members in the list as well.
Robust is used in this context as a metaphor and not it's literal translation, and it is more efficient to directly initialize a variable instead of first initializing it and then later assigning it a value.
This assigns value after initialization.
This assigns value during initialization.
I'm sorry to tell you but this is not true. C++ and MQL4 don't auto-generate code to initialise member variables that are simple types.
It is only imperative to use initialiser lists when the member variables are other classes.
Also I would like to clear up another misunderstanding in this thread.
In MQL4 there's a difference between heap based objects and stack based objects.
- MQL4 classes that are created on the heap with the new operator seem to use "calloc" rather than "malloc" under the covers which zero initialises the buffer before use.
- MQL4 classes that are created on the stack (local variables within functions) do not do this and just map the contents of the current stack onto their structure which are random bytes.
Stack based objects will produce "uninitialized memory reads" (UMR) if the simple instance variables are not set in the ctors.
For performance reasons C++ uses malloc and not calloc so UMR are common with heap as well as stack based objects.
Robust is used in this context as a metaphor and not it's literal translation, and it is more efficient to directly initialize a variable instead of first initializing it and then later assigning it a value.
So you said robust but it's not robust ? I don't understand your metaphor sorry.
This assigns value after initialization.
This assigns value during initialization.
Maybe, maybe not, not sure where you got this information ?
Anyway I checked and there is no significant difference. However this simple test is probably not the more accurate (I saw difference if you inverse the loops, that's why I made 2 functions).
2017.09.19 00:11:23.504 Efficient EURUSD,M5: 1: standard initialization, 1,000,000,000 iterations done in 102,565,131 µs
2017.09.19 00:09:40.938 Efficient EURUSD,M5: 2: initilization list, 1000000000 iterations done in 102216062 µs
2017.09.19 00:07:58.723 Efficient EURUSD,M5: 2: initilization list, 1000000000 iterations done in 102211334 µs
2017.09.19 00:06:16.511 Efficient EURUSD,M5: 1: standard initialization, 1000000000 iterations done in 104452869 µs
By they way, I run the same code on MT5, and I got inverse results, there standard initialization is faster.
2017.09.19 00:20:26.266 1: standard initialization, 1000000000 iterations done in 75675905 µs
2017.09.19 00:21:45.802 2: initilization list, 1000000000 iterations done in 79535963 µs
2017.09.19 00:23:05.121 2: initilization list, 1000000000 iterations done in 79318647 µs
2017.09.19 00:24:21.583 1: standard initialization, 1000000000 iterations done in 76462546 µs
Also notice that MT5 is faster by more than 25% for such a simple thing.