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
I know you can do this, but say you did not know 20 was the max size of q and just want a general initialization
Then assign q to be a Queue of 20 without adding a resize method (which is bad practice, since other generic classes don't have this workaround and resizing to 20 doesn't reset the variable).
EDIT: Is "Queue<double>(20)" bad syntax? If so, what is the equivalent?
Why all these complications ?
Just because you don't want to use a pointer ? Or because you don't want to add a Init() method ? Do you have a solid rationale for these decisions ?
Come on. Adjust your mind to the language and not the reverse.
Why all these complications ?
Just because you don't want to use a pointer ? Or because you don't want to add a Init() method ? Do you have a solid rationale for these decisions ?
Come on. Adjust your mind to the language and not the reverse.
I think you are taking my question out of proportion. I have already stated that I try to avoid pointers if there is no memory-saving reason to. The only other reason to have pointers other than this is polymorphism. I don't hate memory-saving and polymorphism (haha), it is just that I don't think variable declaration I comes under these.
The reason why you should avoid pointers too is because if your program abruptly ends without the OnDeInit()'s you are left with a bunch of floating pointers leaking memory. "When will this happen." An Easy example is every time you run dll code you risk there being an error being in the dll code. Often when this happens the program ends without the OnDeInit() being able to run.
My request was to ask if this code was even possible:
if you don't want to work with pointer why are you using class after all? using a struct shall work as you wish.
If it doesn't work, I will use a pointer or a struct. My question is "Is the pointer-less syntax I asked about possible or does an equivalent exist?"
I think you are taking my question out of proportion. I have already stated that I try to avoid pointers if there is no memory-saving reason to. The only other reason to have pointers other than this is polymorphism. I don't hate memory-saving and polymorphism (haha), it is just that I don't think variable declaration I comes under these.
The reason why you should avoid pointers too is because if your program abruptly ends without the OnDeInit()'s you are left with a bunch of floating pointers leaking memory. "When will this happen." An Easy example is every time you run dll code you risk there being an error being in the dll code. Often when this happens the program ends without the OnDeInit() being able to run.
We are talking about MQL not DLL There is not even real pointer in the language. There is no valid reason to not use a pointer in MQL. The only memory leak you can have will come from the platform, not from your code.
My request was to ask if this code was even possible:
No it's not possible. You can't call a constructor when the object already exists, and the solutions proposed to have copy/assignment constructors are out of proportion with the initial issue. KISS.
No it's not possible. You can't call a constructor when the object already exists, and the solutions proposed to have copy/assignment constructors are out of proportion with the initial issue. KISS.
Thanks this is what I wanted to know.
Why out of proportion ? This is a forum, your topic will stay for the posterity and a lot of people will read it. That's why I think it's important to make things clear. You have a wrong view about pointers in MQL.
We are talking about MQL not DLL There is not even real pointer in the language. There is no valid reason to not use a pointer in MQL. The only memory leak you can have will come from the platform, not from your code.
Interesting, so something like this won't cause a memory leak?
Thanks this is what I wanted to know.
Interesting, so something like this won't cause a memory leak?
In theory yes, so it's not good practice.
Practically no, because MQL4/MQL5 are managed languages. The platform will take care of it, you will get messages about it in the log and the platform will clean it up.
In theory yes, so it's not good practice.
Practically no, because MQL4/MQL5 are managed languages. The platform will take care of it, you will get messages about it in the log and the platform will clean it up.
Thank you!
In theory yes, so it's not good practice.
Practically no, because MQL4/MQL5 are managed languages. The platform will take care of it, you will get messages about it in the log and the platform will clean it up.
^ Good Advice, Regardless of whether you are pointing to memory or controlling object descriptors, the delete operator exists for a reason.