Generic Class Library - bugs, description, questions, usage and suggestions - page 26
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
You create copies of objects in AddValue via new, but you don't release them in the destructor, you just clear the list of pointers.
help says that when you call a destructor, the destructors of the classes you used will also be called
https://www.mql5.com/ru/docs/standardlibrary/datastructures/carrayobj#carrayobjfeatures
I don't remember a case when the terminal didn't write into the log a warning about undestroyed objects after the script was unloaded - my example doesn't show such a warning
Secondly, you should have done it correctly with copy constructor instead of assignment operator. But this all is IMHO)
I've found information from developers that simple structures or classes in MQL are always copied without problems, I've checked it several times and it seems to be true, until I use the language features
This is what the discussion is about - MQL is not C++, I've stopped looking for analogies between them, the developers wrote that this is how it's implemented - I checked it, it works - so you can use it, if the standard C++ syntax is crucial, you can easily write all the logic in .dll
You create copies of objects in AddValue via new, but you don't free them in the destructor, you just clear the pointer list.
Oh, dear! And how can you delete an instance of a class created via new in the destructor. Try to do it. It will not work.
You can do it only in the destructor of some other class.
Oh, shit! And how can you delete an instance of a class created via new in the destructor. You may try it. It will not work.
You can do it only in the destructor of another class.
I was talking about the destructor of another class. I was speaking about items created through new in theAddValue method
help says that when the destructor is called, the destructors of the classes used will also be called
https://www.mql5.com/ru/docs/standardlibrary/datastructures/carrayobj#carrayobjfeatures
i don't remember a case when the terminal didn't write a warning about undestroyed objects into the log after the script was unloaded - my example doesn't show such a warning
i heard from the developers that simple structures or classes in MQL are always copied without any problems, i checked it several times and it seems to be true, so far i use the possibilities of the language
This is what the discussion is about - MQL is not C++, I've stopped looking for analogies between them, the developers wrote that this is how it's implemented - I checked it, it works - so you can use it, if standard C++ syntax is crucial, I should not have to worry about putting all the logic into .dll.
Yes, I saw it in the help... Very implicit thing, looks more like a crutch, instead of unique_ptr...
Yes I saw it in the help... Very implicit thing, more like a crutch instead of unique_ptr...
And it's so handy that I can't even call it a crutch:
Create an object of any class, put it in a storage list, and you don't have to worry about removing it anymore - the terminal subsystem cleans it up by itself.
But you can also set manual operation and "run" for all newly created objects trying to track when, where and for what purposes it was created and whether it is needed now. If it is not needed, delete it. But when you made a mistake, it turns out it was needed - it crashes when accessing an invalid pointer...
So the crutch is just "chasing objects" looking for their uselessness and worrying about memory leaks if some object hasn't been caught up.
Secondly, the correct way to do it is through copy constructor, not assignment operator. But this is all IMHO)
Can you give me an example of how to copy it correctly for this template?
I used help to write AddValue methodhttps://www.mql5.com/ru/docs/basis/types/classes
I racked my brains, but I don't see any other solution in MQL than the one I wrote in my example!
Show me your implementation of correct data storage
And it's so handy that you can't even call it a crutch:
Create any object of any class, put it into storage list, and you don't have to worry about removing it anymore - terminal subsystem cleans it up by itself.
But you can also set manual operation and "run" for all the newly created objects trying to find out when, where and for what purposes it was created and whether it is needed now. If it is not needed, delete it. But when you made a mistake, it turns out it was needed - it crashes when accessing an invalid pointer...
So the crutch is just "chasing objects" looking for their uselessness and worrying about memory leaks if some object hasn't been caught up.
The point here is that once you add a pointer to the collection, it also stays with you. That's the first thing.
help says that when the destructor is called, the destructors of the classes used will also be called
https://www.mql5.com/ru/docs/standardlibrary/datastructures/carrayobj#carrayobjfeatures
i don't remember a case when the terminal didn't write a warning about undestroyed objects into the log after the script was unloaded - my example doesn't show such a warning
i heard from the developers that simple structures or classes in MQL are always copied without any problems, i checked it several times and it seems to be true, so far i use the possibilities of the language
This is what the discussion is about - MQL is not C++, I've given up looking for analogies between them, the developers wrote that this is how it is implemented - I checked it, it works - so you can use it, if the standard C++ syntax is crucial, you can easily write all the logic in .dll
Can a triangular array be made with this?
Due to language limitations, it's unlikely that anything decent will work. I have this crutch (a lightweight wrapper over a standard array).
To store pointers, write a unic_ptr wrapper (although you can't get a full-fledged one, but auto_ptr at least). In my opinion, even such a primitive is much more convenient than std's template counterparts.