Stack overflow in 'C:\Program Files\MetaTrader 4\MQL4\Experts\FxCashEarner Vs.1.0.ex4'

Back to topics list  | 1 2 3 To post a new topic, please log in or register
avatar
145
aakcaagac 2015.11.06 20:50 #
 
Demos:

* I updated my previous post because i included some more code for being able to see the error in the log file 

Of course this is the way the processor work. You can recurse unlimited (or as much stack you gave your program.. or other words, limited to the memory onboard). Java causes a stack pointer exception in this case. Some operating Systems offer dynamic stack adjustment and others have just a fixed stack size of whatever was given to the compiler or whatever limits the operating system (or its underlaying infrastructure). But after all it shouldn't cause the terminal.exe to crash or something like that. Therefore it may be necessary to add some sort of stack boundary protection.

It also matters how the cpu code is being executed.. some bsr, jsr command (branches) usually puts the return value on the stack. If you start recursing to much e.g.

loop:
   moveq #0,d0
   tst.l d0
   beq   loop

or

loop:
   jsr loop
   rts

Then this part of code basicly infinite recurses the loop until a stack overflow happens. This code for example only stores the return address to the stack. Other code variant also stores e.g. address and data registers on the stack like this.

loop:
   movem.l d0-d7/a0-a6,(a7)+
   jsr     loop
   rts

 .. until the stack is filled up. Although the compiler could also use jmp commands rather than jsr or compared branches which doesn't (at least if I recall correctly) store a return value (for what... it jumps and gone)...

To come to an end... Metatrader should handle stack execptions (and even worse division by zero exceptions) far better.. the latter (division by zero execeptions) usually leads to unresponsive (halting) code :) 

avatar
126
Demos 2015.11.06 22:31 #
 
aakcaagac:

Of course this is the way the processor work. You can recurse unlimited (or as much stack you gave your program.. or other words, limited to the memory onboard). Java causes a stack pointer exception in this case. Some operating Systems offer dynamic stack adjustment and others have just a fixed stack size of whatever was given to the compiler or whatever limits the operating system (or its underlaying infrastructure). But after all it shouldn't cause the terminal.exe to crash or something like that. Therefore it may be necessary to add some sort of stack boundary protection.

It also matters how the cpu code is being executed.. some bsr, jsr command (branches) usually puts the return value on the stack. If you start recursing to much e.g.

Then this part of code basicly infinite recurses the loop until a stack overflow happens. This code for example only stores the return address to the stack. Other code variant also stores e.g. address and data registers on the stack like this.

 .. until the stack is filled up. Although the compiler could also use jmp commands rather than jsr or compared branches which doesn't (at least if I recall correctly) store a return value (for what... it jumps and gone)...

To come to an end... Metatrader should handle stack execptions (and even worse division by zero exceptions) far better.. the latter (division by zero execeptions) usually leads to unresponsive (halting) code :) 

my 2 cents here are that i do not believe that a language or cpu architecture should correct logical errors, as a e.g. situation of infinite loop; a OS looks more appropriate (to me at least) for such a task - or  a virtual machine as we speak

Also, i have not any clue of assembly :) I might learn one day if i need to - for example if it makes sense on some embedded processors i may use :)

 

best regards 

avatar
145
aakcaagac 2015.11.06 22:51 #
 
Demos:

my 2 cents here are that i do not believe that a language or cpu architecture should correct logical errors, as a e.g. situation of infinite loop; a OS looks more appropriate (to me at least) for such task - or  a virtual machine as we speak

I am with you here. A language or CPU architecture (to say so) should not correct logical errors. But in terms of Metatrader (as a software and trading platform) it should cover such issues a bit better than it actually does. Whatever happens, at least Metatrader shouldn't crash (e.g. your indicator shouldn't crash the underlaying mother process (in this case Metatrader)). This is more or less a design decision. We are here on a user level. A tool or a piece of software that deals with money on a daily base.
avatar
49
Opengates 2015.11.09 07:59 #
 

I am grateful to all for their contributions.

I will take my time to read each suggestion to my understanding and implement it as deem fit until I get it right.

I will definitely get back to you on far I have gone with it.

You are all the best. Thanks for your support, I feel like I'm in a family and really indeed, it is a family of

selfless programmers irrespective of individual's level and knowledge.

You are all blessed.

Opengates
Back to topics list   | 1 2 3  

To add comments, please log in or register