Download MetaTrader 5

Abnormal program termination

To add comments, please log in or register
Move from theory to practice. Code Base will help you!
Martin Fronek
70
Martin Fronek 2010.10.06 12:29 

Hi,


I have coded a DLL which works fine most of the time, but if I leave it running for 10-20 hours, an "abnormal program termination" occurs (I run it on 2 charts and it seems to occur on both of them at once).


I have absolutely no clue what could cause it. Can somebody please answer these questions:


1. What are the most common causes of "abnormal program termination"?

2. How do I prevent it from occuring in C++ (some error handling I guess, but I didn't find the right way)

3. How do I - if possible - prevent it from occuring on MQL4 side?


Thank you

Martin

zzuegg
1505
zzuegg 2010.10.06 12:38  

if the same error happend after a a long time running.(normally 20hour should not be considert as long) i guess you are allocating memory at each call and you don't free the whole.


//t

Martin Fronek
70
Martin Fronek 2010.10.06 12:44  
zzuegg:

if the same error happend after a a long time running.(normally 20hour should not be considert as long) i guess you are allocating memory at each call and you don't free the whole.


//t


Can you elaborate please, I'm new to C++ and I actually "learned" it just to be able to build this DLL.


What exactly is memory allocation and how do I free it?


I created a segment so that the values counted once don't have to be re-counted at each tick, as it takes quite a lot of time (like 2 seconds):


#pragma data_seg (".myseg")
string vls = "";
int rchck = 0;
#pragma data_seg()

#pragma comment(linker, "/section:.myseg,RWS")


Is this where the problem is or does "allocating memory" mean something else?


Thank you very much in advance.

bernd
985
bernd 2010.10.06 12:56  
Fromin:

I'm new to C++ and I actually "learned" it just to be able to build this DLL.

Why did you chose from all languages that exist on this planet the most complicated and error prone language currently known to mankind (namely C++) to make your DLL? Especially if you are new to programming?
Martin Fronek
70
Martin Fronek 2010.10.06 12:59  
7bit:
Why did you chose from all languages that exist on this planet the most complicated and error prone language currently known to mankind (namely C++) to make your DLL? Especially if you are new to programming?

Well not that it would change anything now when it's almost complete, but what language should I have used? :-)


Don't want to get this thread too off-topic though, do you zzuegg know the answer to my question? Or anybody else? Thank you

bernd
985
bernd 2010.10.06 13:22  

try to get a more useful crash report: at what address in which module did it happen, what exactly happened, maybe you can even get a useful stack trace. If the MT4 built in exception handler does not pop up then try to install your own exception handler to create the crash report and/or the stack trace or try to attach a debugger to the process and see if this helps getting more information.

"Abnormal program termination" is not a useful error description. Everything that is not "normal" is "abnormal" by definition. This does not help. Try to get more information.

Martin Fronek
70
Martin Fronek 2010.10.06 14:22  
7bit:

try to get a more useful crash report: at what address in which module did it happen, what exactly happened, maybe you can even get a useful stack trace. If the MT4 built in exception handler does not pop up then try to install your own exception handler to create the crash report and/or the stack trace or try to attach a debugger to the process and see if this helps getting more information.

"Abnormal program termination" is not a useful error description. Everything that is not "normal" is "abnormal" by definition. This does not help. Try to get more information.



Thanks, will do.


In the meantime, can someone (or zzueg himself) englighten me about the first answer? Thank you


Fromin:

Can you elaborate please, I'm new to C++ and I actually "learned" it just to be able to build this DLL.

What exactly is memory allocation and how do I free it? I created a segment so that the values counted once don't have to be re-counted at each tick, as it takes quite a lot of time (like 2 seconds):


#pragma data_seg (".myseg")

string vls = "";

int rchck = 0;

#pragma data_seg()

#pragma comment(linker, "/section:.myseg,RWS")


Is this where the problem is or does "allocating memory" mean something else? Thank you very much in advance.


bernd
985
bernd 2010.10.06 16:42  
Fromin:

In the meantime, can someone (or zzueg himself) englighten me about the first answer? Thank you

You cannot expect to be able to write even the most trivial programs in C++ (or any other similar low level language) without knowing anything about memory allocation and the difference between stack and heap and how your data is represented in the hardware and how things work and what is happening on this low level.


If you are writing programs that run directly on the hardware and manipulate data directly on the hardware you are supposed to know how the hardware works (what is memory, how is it organized (what is heap, what is stack, what is used for what and how and why), how is your data represented, how does a CPU work, what else is going on). A deep understanding of all this is needed for writing programs in these languages.

After all C is not much more than a powerful macro assembler with some neat assembler macros that almost look like a high level language and C++ is essentially just some more syntactic and grammatic sugar and a bunch of even more powerful macros on top of that, but its still a very low level language and it is commonly (amongst the C++ masochists) seen as a great feature that the language is "designed" in such a way that you can shoot yourself into the foot whenever you want, even when you don't want it.


If you really want to go this route I suggest you start with C (not C++) and try to make yourself comfortable with malloc() & friends and learn to manipulate strings and other data structures and mess around with pointers to your data on this low level until you understand exactly what is going on in your computer in every detail when your small C program runs. Then after some months you might proceed to C++ and learn about classes and object instances, inheritance and virtual methods, construction and destruction of objects and all that stuff (and what this all implicates in the absence of a garbage collector) and and then you may use the string class (this time knowing exactly what it does behind the scenes).

JC
1456
JC 2010.10.06 17:19  
zzuegg:

if the same error happend after a a long time running.(normally 20hour should not be considert as long) i guess you are allocating memory at each call and you don't free the whole.

Personally, I'd be a little surprised if it was running out of memory without that being immediately obvious from other problems on the computer.

I'd check that there are no problems with the DLL function being called simultaneously from multiple threads. Unexpected function re-entrancy is a common cause of problems which don't emerge immediately. Albeit I'd still expect such a problem to occur within less than 10-20 hours.

Martin Fronek
70
Martin Fronek 2010.10.06 19:49  
7bit:

You cannot expect to be able to write even the most trivial programs in C++ (or any other similar low level language) without knowing anything about memory allocation and the difference between stack and heap and how your data is represented in the hardware and how things work and what is happening on this low level.


If you are writing programs that run directly on the hardware and manipulate data directly on the hardware you are supposed to know how the hardware works (what is memory, how is it organized (what is heap, what is stack, what is used for what and how and why), how is your data represented, how does a CPU work, what else is going on). A deep understanding of all this is needed for writing programs in these languages.

After all C is not much more than a powerful macro assembler with some neat assembler macros that almost look like a high level language and C++ is essentially just some more syntactic and grammatic sugar and a bunch of even more powerful macros on top of that, but its still a very low level language and it is commonly (amongst the C++ masochists) seen as a great feature that the language is "designed" in such a way that you can shoot yourself into the foot whenever you want, even when you don't want it.


If you really want to go this route I suggest you start with C (not C++) and try to make yourself comfortable with malloc() & friends and learn to manipulate strings and other data structures and mess around with pointers to your data on this low level until you understand exactly what is going on in your computer in every detail when your small C program runs. Then after some months you might proceed to C++ and learn about classes and object instances, inheritance and virtual methods, construction and destruction of objects and all that stuff (and what this all implicates in the absence of a garbage collector) and and then you may use the string class (this time knowing exactly what it does behind the scenes).

No time for that, I'll be happy if I get this one working :D
zzuegg
1505
zzuegg 2010.10.06 20:35  

i am still betting on the memory handling.

but if you are not willing to lear code correctly it seems that you have to restart your terminal every 20 hours. and btw, this is not a c++ forum, but i give you the advise to not ask in a advanced c++ forum what malloc() and free() is.

//z

12
To add comments, please log in or register