Thanks to the author for the library!
Wrote the functions to transfer any data. Below the script shows their work on the example of ticks
#include <MemMapLib.mqh>
#include <TypeToBytes.mqh>
// Selects the specified length memory for data
template <typename T>
bool GetFileMemory( CMemMapFile* &FileMemory, const int Amount, const string FileName = "Local\\test" )
{
FileMemory = new CMemMapFile;
return(FileMemory.Open(FileName, sizeof(T) * Amount + sizeof(int) + HEAD_MEM, modeCreate) == 0);
}
// Writes data to memory
template <typename T>
void DataSave( CMemMapFile* FileMemory, const T &Data[], const bool FromBegin = true )
{
const int Size = ArraySize(Data) * sizeof(T);
uchar Bytes[];
_ArrayCopy(Bytes, _R(Size).Bytes); // Copied quantity
_ArrayCopy(Bytes, _R(Data).Bytes, sizeof(int)); // Copied data
if (FromBegin)
FileMemory.Seek(0, SEEK_SET);
FileMemory.Write(Bytes, ArraySize(Bytes)); // Have dumped all in memory
return;
}
// Reads data from memory
template <typename T>
int DataLoad( CMemMapFile* FileMemory, T &Data[], const bool FromBegin = true )
{
if (FromBegin)
FileMemory.Seek(0, SEEK_SET);
uchar Bytes[];
FileMemory.Read(Bytes, sizeof(int)); // Read from memory the amount of data
FileMemory.Read(Bytes, _R(Bytes)[0]); // Received the data itself
_ArrayCopy(Data, Bytes); // Reset the data in an array
return(ArraySize(Data));
}
#define AMOUNT 1000
#define TOSTRING(A) #A + " = " + (string)(A) + " "
// Example of forwarding ticks
void OnStart()
{
CMemMapFile* FileMemory;
if (GetFileMemory<MqlTick>(FileMemory, AMOUNT))
{
MqlTick Ticks4Save[];
CopyTicks(_Symbol, Ticks4Save, COPY_TICKS_INFO, 0, AMOUNT);
DataSave(FileMemory, Ticks4Save);
MqlTick Ticks4Load[];
if (DataLoad(FileMemory, Ticks4Load) > 0)
Print(TOSTRING((_R(Ticks4Save) == Ticks4Load)) +
TOSTRING(ArraySize(Ticks4Save)) +
TOSTRING(ArraySize(Ticks4Load)));
FileMemory.Close();
}
delete FileMemory;
}
Result
(_R(Ticks4Save)==Ticks4Load) = true ArraySize(Ticks4Save) = 1000 ArraySize(Ticks4Load) = 1000