How to save dynamic array to file - page 2

 
Dominik Egert:

Here is a code snippet to find out how fast a code is executed.

Actually now I have to start some experiments. So, in order to make a plan before I will start, would like to ask, which formats have good potential for optimal read write dynamic array, including strings. 

As far as I can see so far, TXT, CSV and JSON ar good candidates.

 
Fernando Carreiro:

Instead of asking, experiment for yourself and find out! 

If you will have to choose, which format would you prefer to read/write dynamic array including string, TXT, CSV or JSON as recommended by Dominik?

 
Narek Kamalyan: If you will have to choose, which format would you prefer to read/write dynamic array including string, TXT, CSV or JSON as recommended by Dominik?
None of the above! I would choose to use a packed binary format, because files would be smaller, read and write would be quicker, and there would be no need to waste time with conversion to and from text format.
 
Fernando Carreiro:
None of the above! I would choose to use a packed binary format.
What is packed binary (((
Do you have any piece of sample code. 
Or any source of information, mql5 documentation doesn’t show any relevant information. 
 
Narek Kamalyan: What is packed binary ((( Do you have any piece of sample code. Or any source of information, mql5 documentation doesn’t show any relevant information. 

Packed binary is just binary data packed sequential in way that is not byte aligned to anything, so there is no space between data.

There are already examples in the documentation using packed binary data, such as the example at "FileWriteDouble()" or "FileWriteLong()".

 

Also, instead of your 2 dimensional array, create an array of a structure and simply use the FileWriteArray(), but remember to first output the size of the array, with FileWriteIntger(), so that you can dynamically adjust when reading it back.

EDIT: The array size is only needed in the case that you output other data to the file! If you only output the single array to it, then there is no need to save the size to the file as MQL will automatically adjust the size of a dynamic array for it when reading it. See the example FileReadArray().

Documentation on MQL5: File Functions / FileReadArray
Documentation on MQL5: File Functions / FileReadArray
  • www.mql5.com
FileReadArray - File Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro:

Also, instead of your 2 dimensional array, create an array of a structure and simply use the FileWriteArray(), but remember to first output the size of the array, with FileWriteIntger(), so that you can dynamically adjust when reading it back.

I am using structure array. And I have seen the page you sent to me. But it says strings cannot be written into bin. This is why I am looking for workaround. Or I missed something?
 
In my case, structure two dimensional dynamic array contains strings. Is bin compatible format?
 
Narek Kamalyan:
In my case, structure two dimensional dynamic array contains strings. Is bin compatible format?
No. Read the documentation please.
 
Alain Verleyen:
No. Read the documentation please.
Hi Alain
Actually Fernando recommended to use bin in my particular case this is why I tried to clarify. 
Then what is the proper file format in this case. 
Reason: