Are arrays of mql5 structs stored reliable complete in one piece in memory? - page 2

 
Alain Verleyen #:

mql5 is not an interpreted language. It's compiled and managed language.

Of course mql arrays are contiguous in memory. It's implicit from the documentation and experience. If you want to prove it otherwise please do it and show us.

I could not find anything clear in the documentation. I don't want to prove the opposite but i want to make sure that you can rely on contiguous memory because i want to access this data with dll. Machines manage money so i don't want to leave anything to coincidence.

 
Alexandre Borela #:
No, again you are confusing containers with arrays. I said I implemented C++'s containers in MQL (one of them is the vector)
which uses arrays as its storage medium, and, the arrays are behaving as expected.

You still didn't answer my question, have you implemented something where the arrays are not behaving as expected?
No so far, but i haven't tested it extensively yet. My concern is just to be sure because it manages real money. I don't want any surprises. With mql there are already surprises from time to time :-)
 
4lpha #:

I could not find anything clear in the documentation. I don't want to prove the opposite but i want to make sure that you can rely on contiguous memory because i want to access this data with dll. Machines manage money so i don't want to leave anything to coincidence.

If you read the documentation about ArrayResize() and experiment it, it's pretty obvious it's contiguous, for example it may happens ArrayResize() returns an error because it can't find a contiguous block of memory to allocate though you still have enough free memory. Actually it's a non sense to think an raw array could be implemented otherwise that with a contiguous memory block.

I am 100% sure it's contiguous, but I can't prove it "scientifically".

I understand your concern, but there are a lot of other things to take care of when talking about robustness and reliability of financial software.

 
4lpha #:
No so far, but i haven't tested it extensively yet. My concern is just to be sure because it manages real money. I don't want any surprises. With mql there are already surprises from time to time :-)

If you are not trying to access price/indicator buffers which will get reallocated(but will still remain contiguous) when the chart loads more bars, there's should be any problems accessing arrays.

 
Alexandre Borela #:

Sure you can in C++, resizing an array is just a matter of allocating the new memory, copy the contents to the new array,
deallocate the old array and return the address of the new array.

The fact the MQL is doing a single function call, is mere convenience.

Again, don't confuse std::array(which is a container) with array, they are not the same thing in C++.

All right, you are talking about C-style arrays. In C++ normal you use std containers with rezise functions (like MQL) so I referred to that. We don't know 100% what is behind the MQL array.
I also believe that the MQL array is in RAM in one piece but in the end it manages money and I want to be sure :-)

 
4lpha #:

All right, you are talking about C-style arrays. In C++ normal you use std containers with rezise functions (like MQL) so I referred to that. We don't know 100% what is behind the MQL array.
I also believe that the MQL array is in RAM in one piece but in the end it manages money and I want to be sure :-)

I rarely see people using std::array, to me it's more common to see them either using the builtin arrays(C style)
or the std::vector when the size it is not known. This is why I just distinguish them as array x containers.

Even if they use std::vector as the underlying data type, it still uses "C style arrays" internally which are contiguous.
 
Alain Verleyen #:

If you read the documentation about ArrayResize() and experiment it, it's pretty obvious it's contiguous, for example it may happens ArrayResize() returns an error because it can't find a contiguous block of memory to allocate though you still have enough free memory. Actually it's a non sense to think an raw array could be implemented otherwise that with a contiguous memory block.

I am 100% sure it's contiguous, but I can't prove it "scientifically".

I understand your concern, but there are a lot of other things to take care of when talking about robustness and reliability of financial software.

Ok good to know, well agree with ArrayResize() another indication that it is as hoped. And jes true words, there are a lot of other things to take care of :-)

 
Alexandre Borela #:
I rarely see people using std::array, to me it's more common to see them either using the builtin arrays(C style)
or the std::vector when the size it is not known. This is why I just distinguish them as array x containers.

Even if they use std::vector as the underlying data type, it still uses "C style arrays" internally which are contiguous.

Jes, most simply use the std::vector you can use it for almost everything an it is more practical than std::array (cause resize) and almost identically fast.
It's true, the containers are just something like wrappers for c-arrays with various useful or superfluous functions.

 
After carefully reading the docs about arrays, I would see the part about ArrayResize as strong evidence for arrays to be as in C/C++


Especially the explanation about pre allocation gives strong hints to be true.

Additionally, the documentation on static arrays as members of structures supports this further.

https://www.mql5.com/en/docs/basis/variables#array_define