Libraries: File Mapping without DLL - page 10

 
o_o:

At least you don't try to read a file in memory after restarting the computer...


So I understand that I cannot transfer data through memory between two terminals in this way?

And what is the correct way? I need to implement the transfer of a text string from one terminal to another using MemMapLib.mqh.

 
Иван:

So I understand that I can't transfer data through memory between two terminals in this way?

you can

You need to implement the transfer of a line of text from one terminal to another using MemMapLib.mqh.

create a file, write it, then read it.

roughly in this order

https://www.mql5.com/en/code/10571

 
        CMemMapFile hmem;
        long err=hmem.Open("Local\\test",111,modeCreate);

What is the maximum amount of data I can write to an open file in memory and then read?

After 4096 the Expert Advisor starts crashing at this point.

 
Give me the code and the pinout
[Deleted]  
HANDLE64 CMemMapFile::Open(LPTSTR path, DWORD size, int mode=modeOpen) 
{ 
m_size=size; m_path=path; m_mode=mode; m_pos=0; // начальное положение 
if (m_path=="") return(-1); 
m_hmem=Open(m_path, size, mode, err); 
if (m_hmem==NULL) return(err); // если ошибка создания 
return(0); 
} 

Hi, in the code above "return(0)" should be corrected into "return(m_hmem)", otherwise it wont return the handle of memory mapped file.

 

I tried to write a 200 characters long string to a file, I got an error of exceeding the array size in line 214 of the library. It turns out that the header size is not taken into account when determining the size of the receiving array.

 
Алексей Барбашин:

It's working.

doesn't work.

Give me the code and the spindle

 
o_o:

It's not working.

Give me the code and the printout


   string control_text = "Our mummy's crying loudly because everyone's pigging out. Hush mummy, don't cry! The others have the same shit...";
   string NAME_MAPPING = "Local\\" + Symbol() + "_" + (string)ChartID();
        
   uchar Data_sender[];
   int size_data = StringToCharArray(control_text, Data_sender);

  //--- Create a memory object
   CMemMapFile* MappingFile = new CMemMapFile();
  //--- Create a file for recording
   long err = MappingFile.Open(NAME_MAPPING, size_data+4, modeCreate);
        
  //--- Write data to file
   err = MappingFile.Write(Data_sender, size_data);
        
  //--- Close the record
   MappingFile.Close();
  //--- Delete the pointer
   delete MappingFile;
   
   uchar Data_receiver[];
   ArrayResize(Data_receiver, size_data);
   
   //--- Create a memory object
   CMemMapFile* MF = new CMemMapFile();
   //--- Open the file for reading
   err = MF.Open(NAME_MAPPING, size_data+4, modeOpen);
   //--- Сдвигаем указатель чтения на начало файла
   MF.Seek(0,SEEK_SET);
   //--- Читаем данные из файла
   err=MF.Read(Data_receiver, size_data);
   //--- Close the file 
   MF.Close();
  //--- Delete the pointer
   delete MF;

   Print(CharArrayToString(Data_receiver));

I've figured out the dimensions. But I tried to read the file with another object and got silence on the output. Where is the error?

 
Алексей Барбашин:

I figured out the dimensions. But I tried to read the file with another object and got silence on the output. Where is the error?

//--- Close the record

It's not called closing a record, it's called closing and deleting a file.

That's why

//--- Open the file for reading
you're trying to open something that doesn't exist.
 
o_o:

it's not called closing the record, it's called closing and deleting the file.

which is why

you're trying to open something that doesn't exist.

Okay, that makes sense. I was following the analogy of working with regular files, when closing leads exactly to closing and releasing, not deleting the file.