Tips on coding very memory-efficient?

 

I wonder if anyone has any really helpful tips on using the least amount of memory possible, or at least at freeing it again.

I'm working on a really big multi-currency EA, using quite some indicators. But still this should not pose any problems for modern computers with 20GB of RAM or thelike.


Recently, I started to have "no memory in OnTick function...", which by the way is pretty "funny" as I don't have an OnTick function. But so I think about what I might have done wrong, or what others are doing "more right". I know there's the issue with Indicator Release, but that shouldn't have an influence on my current project.

I wonder more, would you advise on things like:

.) ZeroMemory each variable as soon as it's not needed anymore, but at least at the end of a method.

.) but brackets {} around blocks with temporary variables, so they are "forgotten" immediatly afterwards.

.) ArrayResize(var,0) as soon as an array is no longer needed.

and so on. I know, basically all variables should be deleted at the end of their method (unless static or part of a class or thelike of course). But has anybody made any discoveries, that things like that would help MQL with memory management?


I don't want to spend hours on ie putting hundreds of brackets into my code, if it doesn't yield any improvement. So your help and input is highly appreciated.

Thanks in advance, Clock

 
Clock:
have you found any solution for your problem , as i'm facing the same here :(
 
Declare some variable in global instead of ontick or ontimer
 

Not really a solution, as I didn't have a problem zu solve...


@Doshur: why would that make more sense? Shouldn't you always declare variables on the lowest level possible?

Clock

 
Clock:

Not really a solution, as I didn't have a problem zu solve...


@Doshur: why would that make more sense? Shouldn't you always declare variables on the lowest level possible?

Clock

I used to declare trade classes inside ontick() and later found that it should be declare in the global state.

i ran some performance test in the strategy tester and was slightly faster. 

 
doshur:

I used to declare trade classes inside ontick() and later found that it should be declare in the global state.

i ran some performance test in the strategy tester and was slightly faster. 

@doshur .. in case classes , yes you are right .. but in my case am not using classes or structures .. just a group of variables 

@Clock .. it is not a problem in the strategy tester (although it is slow but works well), but the optimization cant finish more than 100 out of 8000 test cases .. even if am using cloud
, also "
no memory in OnTick function"  it is an error i cant find a cause or a solution for it Yet ..

thanks for your reply doshur and Clock :)

 

then you need to look through your code to see where you can improve on.

Sometimes I still see my code still can be "upgraded" to be more efficient.

 
This might be obvious, but one is use the smallest data type that will get the job done. For example use char if you only need max 256 values instead of short or int.
 
This article:Decreasing Memory Consumption by Auxiliary Indicators can also be helping in some cases.
Reason: