Libraries: File Mapping without DLL - page 3

 
Urain:
I guess we have to do some kind of guaranteed test. But I don't know how yet.

Logically speaking, closing a handle causes the memory area to be freed.

But it doesn't mean that closing the handle should clear this area to zero. The handle is closed, the written data remains until it is overwritten by other software. that's how it is.

 
sergeev:
If you use files for storing intermediate data, you can, of course. The main thing is to reset the data to disc at some reference points, because if something happens, the information will be irretrievably lost.
If "something happens", the actual information will be lost in any case. And intermediate results, yes, you can periodically dump to a file on the railway.
 
sergeev:

Logically speaking, closing the handle will free this memory area.

But it doesn't mean that closing the handle should clear this area to zero. Handle closed, the written data remains until they are overwritten by other software. so it goes like this.

The file is closed, the handle is destroyed, we open a file with the same name and read the necessary information, although by idea the distributed area should be lost and opening a destroyed file without creating it should cause an error. I don't know if this is a bug or a feature.

#include <MemMapLib.mqh>
//+------------------------------------------------------------------+
//| Script programme start function|
//+------------------------------------------------------------------+
void OnStart()
  {
   CMemMapFile *hmem=new CMemMapFile();
   int err=hmem.Open("Local\\test",111,modeCreate);// create a file

   uchar data[];
   int sizedata=StringToCharArray("Hello from MQL5!",data);
   err=hmem.Write(data,sizedata);  // write
   ArrayInitialize(data,0);

   CMemMapFile hm;
   err=hm.Open("Local\\test",111); // open the file, without creating
   uchar nextdata[];
   hm.Seek(0,SEEK_SET);
   err=hm.Read(nextdata,sizedata); // read
   Print(CharArrayToString(nextdata));

   ArrayInitialize(data,0);
   err=hmem.Open("Local\\test",111); // open the file, without creating
   hmem.Seek(0,SEEK_SET);
   err=hmem.Read(data,sizedata);     // read
   Print("to ",CharArrayToString(data));

   hmem.Close(); delete hmem; // close the file
   hm.Close();                // close the file

   ArrayInitialize(data,0);
   err=hm.Open("Local\\test",111);Print("err=",err);
   hm.Seek(0,SEEK_SET);
   err=hm.Read(data,sizedata);
   Print("after ",CharArrayToString(data));
  }
//+------------------------------------------------------------------+
 
Urain:

although the distributed area should be lost and opening a destroyed file without creating it should cause an error.

I think it's a bug.

The trick is that there is a file name in memory. And the system detects it.

 

Folks, I have a request.

I need to find such an API function - from any API, including non-windows ones - that will not allow to use memcpy/strcpy .

i.e. find a case when for some reason the size of the returned pointer will not be known, or the returned string will be not NULL-terminated and without known size.


Please help me to find the limits of this method's application...

 

MT5 642 Win7 64 does not work, as far as I understand it, after

hmem=CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_READWRITE,0,size+HEAD_MEM,path); // create memory object

I get error 1400,

but Vista 32 works.

 

I checked, I got the same error. But =6.

 
sergeev:

I checked, I got the same error. But =6.



It must be a trick of some kind. At direct launch it gives err=6, but in debug mode err=1400.

 
How to transfer int or double arrays? I can't do it :(
 
baramantan:
How to transfer int or double arrays? I can't do it :(
treat them as long variables of sizeof(<Type>)*<Number_Elements> and everything will work :)