Library instances

 
Hi,

I noticed that when calling external dll's, the terminal shares the same instance among all experts. How is it with mq4 libraries? Can I save states in a lib variables or is it too shared among all experts?

Thanks,
Doji
 
Please read MetaEditor dictionary. Program Run - Imported functions call
===
Unlike system libraires, custom libraries (MQL4) are loaded for every calling module separately, independently on whether the called library has been loaded by any other module. For example, the caller.ex4 module calls functions from lib1.ex4 and lib2.ex4 libraries. The lib1.ex4 library, in its turn, calls functions from the lib2.ex4 library. In this case, one more copy of the lib1.ex4 library and two copies of the lib2.ex4 library will be loaded, regardless that all calls come from the same caller.ex4 module.
===
 

Yeah... This must be definitely considered as a bug. I mean, basically, this behaviour is a serious "performance and reuse killer". The whole EX4 late binding policy actually means, that when I need to call a method (which is defined in module A) from at least two places: from module B (which depends on module A) and from module C (which depends on both module B and on module A directly), I get an unnecessary memory/cpu consumption.

Ok, the latter kills performance - what's with reuse? Imagine this method relies on some state of module A (say some variable is being written and read). If I call this method (which belongs to module A) from module B, which sets a value to some variable (which is defined in module A) and when from module C I invoke another method (which also belongs to module A), which reads the same variable, I get a value of 0, because the new instance of module has been initialized. So here I stuck with two independent instances, that change their own copies of independent variables? Ouch...

My point here is: you cannot properly share state of one module between other modules. This in turn means, we have very poor means of bastraction in MT4 and this single means of abstractions that actually works is methods (functions, in other word) - component level abstraction just doesn't work. Now we've come to a conclusion, where I would like to ask some "why" questions...

Why would we need dynamic modular loading and binding support, if it doesn't work? Why, if we anyway end up writing the whole code in a single file (module)?

Why would we want to write separate modules if it's not for reusability purposes?

The point is, we are literally unable to build more or less complex systems without the risk of being lost in our own code. This may probably seem like too more about designing of code, but believe me, if you are serious about writing an automated experd advisor (that works), you will have to take desining and reuse questions into consideration.

My last question is, how is it going to be (or probably is) in MT5? Has it already been or is it going to be fixed?


Thanx,

Jevgeni

Reason: