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
https://www.mql5.com/en/docs/basis/variables/local#stack
In every MQL5 program, a special memory area called stack is allocated for storing local function variables that are created automatically.
Static local variables are stored in the same place where other static and global variables are stored - in a special memory area, which exists separately from the stack. Dynamically created variables also use a memory area separate from the stack.
With each function call, a place on the stack is allocated for internal non-static variables. After exiting the function, the memory is available for use again.
Therefore, for large local data you should better use dynamic memory - when entering a function, allocate the memory, which is required for local needs, in the system (new, ArrayResize()), and when exiting the function, release the memory (delete, ArrayFree()).What memory area do local objects (instances of a class) with an automatic pointer use?
What memory area do local objects (instances of a class) with an automatic pointer use?
Thanks for your answer.
I can't say I completely understood😄 I need to figure this out... Looks like this requires C++ knowledge
Thanks for your answer.
I can't say I completely understood😄 I need to figure this out... Looks like this requires C++ knowledge
I'm trying to understand whether allocating memory to an object is costly in terms of performance.
With each tick, I collect all current orders into one complex object (which consists of other objects). I'm guessing that the total size of this object is about one kilobyte.
I'm wondering if the EA would work faster if this object existed all the time instead of being created and deleted every tick.
I believe that given the small size of the object, the time spent on memory allocation can be neglected. But I can't be sure about it.
I collect all current orders into one complex object (which consists of other objects)
I'm talking about market and pending orders in MT4 (not historical). This is just a clarification so that you understand my example correctly. The topic is devoted to MQL5
I'm trying to understand whether allocating memory to an object is costly in terms of performance.
With each tick, I collect all current orders into one complex object (which consists of other objects). I'm guessing that the total size of this object is about one kilobyte.
I'm wondering if the EA would work faster if this object existed all the time instead of being created and deleted every tick.
I believe that given the small size of the object, the time spent on memory allocation can be neglected. But I can't be sure about it.
So test it. With the Strategy Tester you can easily check that and see what is faster.
In general, even a small improvement can be very useful if you are using optimizations. Even if it's negligible when running on a live chart.
So test it. With the Strategy Tester you can easily check that and see what is faster.
In general, even a small improvement can be very useful if you are using optimizations. Even if it's negligible when running on a live chart.
I'll try to check this in the next couple of days.
But first I can conclude that in most cases this is not advisable (for small data). This makes the code more cumbersome and inconvenient. Accordingly, it increases the cost of writing code and changing it in the future if necessary.
If you imagine that this will give some kind of performance gain on small objects, then with this logic you can abandon OOP, make all variables global and not use functions - macros at most😄
I'll try to check this in the next couple of days.
But first I can conclude that in most cases this is not advisable (for small data). This makes the code more cumbersome and inconvenient. Accordingly, it increases the cost of writing code and changing it in the future if necessary.
If you imagine that this will give some kind of performance gain on small objects, then with this logic you can abandon OOP, make all variables global and not use functions - macros at most😄
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".