This is mainly something for the compiler and hardware. Not something for average MQL coder.
The example in the second video with the double loops is very bad. Unfortunately we can't check the assembler code produce by MQL compiler, but here is the C++ result :
MQL coders don't have much to worry about "branches in your code".
I think the code was not about a real example, but to demonstrate something.
The assembly you have gotten from the compiler was optimized, and removed the branch. That was not the point, it was about to show what happens, if the branch predictions fail, and how costly this is on the CPU level.
But to pu5 this into perspective, if you happen to clear out the pipeline and discard the results of 10 OPs, it would probably be maybe around up to 400 CPU cycles or so. On today's CPUs this would be 0.00000002 seconds. (Discard + reprocess).
But to some extend, doesn't this contradict your statement in this post?
I think the code was not about a real example, but to demonstrate something.
The assembly you have gotten from the compiler was optimized, and removed the branch. That was not the point, it was about to show what happens, if the branch predictions fail, and how costly this is on the CPU level.
But to pu5 this into perspective, if you happen to clear out the pipeline and discard the results of 10 OPs, it would probably be maybe around up to 400 CPU cycles or so. On today's CPUs this would be 0.00000002 seconds. (Discard + reprocess).
But to some extend, doesn't this contradict your statement in this post?
Thank you very much for your answers, Alain and Dominik. For me personally, the discussion that began with post 11 led to a better understanding of how memory and processor work.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
This is mainly something for the compiler and hardware. Not something for average MQL coder.
The example in the second video with the double loops is very bad. Unfortunately we can't check the assembler code produce by MQL compiler, but here is the C++ result :
MQL coders don't have much to worry about "branches in your code".
Please explain us, MQL coders, how you "avoid branches in your code" ? And how it improves performance ?
Can I expect the default constructors of member objects to be called before the constructor body starts executing?
The following test shows that it works:
But can I expect this to work always (I didn't find anything in the documentation about this)?
Or is it better to explicitly call the default constructors for member objects in the initialization list?
That is, is what I highlighted redundant?
Is it necessary to check a pointer before deleting an object?
Here is a typical case of unsuccessful EA initialization
Is this code correct? Deleting a non-existent object does not cause runtime errors. Or is it better to do it like this:
Can I expect the default constructors of member objects to be called before the constructor body starts executing?
The following test shows that it works:
But can I expect this to work always (I didn't find anything in the documentation about this)?
Or is it better to explicitly call the default constructors for member objects in the initialization list?
That is, is what I highlighted redundant?
Why does the following code work?
Is implicit downcast allowed?
Why does the following code work?
Is implicit downcast allowed?
Interesting. There is no downcast as m_ptr is actually pointing to a CDerived object, if it was pointing to a CBase one it would give a runtime error.
The compiler should probably better give a warning about it.