Libraries: Memory Mapping

 

Memory Mapping:

DLL (MS VC++ 2010) for working with Memory Mapped files.

Example: Quotes Monitoring (memory-mapped file)

Author: Alex Sergeev

 

May be useful to someone:

Alternatively, you can make a RAM disc and place files there. Ram disc is a virtual disc located in the RAM of your computer.

I use such software to create a Ram disc http://ramdisk.nm.ru/ramdiskent-rus.htm

 

I wish it all could be written into MQL so that it could be used without dll.

Thanks Alex, cool stuff.

 
Urain:

It would be nice if all this could be implemented in MQL so that it could be used without dll.

Unfortunately, the whole problem lies in one single function - MapViewOfFile. It returns a pointer, so you can't use it directly in MQL... you can't bring a pointer to an array.

All other functions (there are only 4 of them -CreateFileMapping, OpenFileMapping, UnmapViewOfFile, CloseHandle) can be called.
but only this MapViewOfFile did not give the opportunity to create a fully functional work from MQL with mapping directly. and it's a pity, I also really wanted to do it without a self-written DLL.

 
sergeev:

Unfortunately, the whole problem lies in one single function - MapViewOfFile. It returns a pointer, so you can't use it directly in MQL... you can't bring a pointer to an array.

All other functions (there are only 4 of them -CreateFileMapping, OpenFileMapping, UnmapViewOfFile, CloseHandle) can be called.
but only this MapViewOfFile did not give the opportunity to create a fully functional work from MQL with mapping directly. and it's a pity, I myself also really wanted to do without a self-written DLL.

Actually it's not you, the message was to MQ developers, the problem is old and its solution is obviously in demand.

ZY I wrote functions of passing pointers to array via event for similar purposes (but inside one MT), but it didn't work without dll either, though functions in dll were single line.

 
Urain:

Actually it's not you, the message was to MQ developers, the problem is old and its solution is obviously in demand.

Oh yeah, what's needed is needed.

Have you ever done anything to create a converter function?

For example, some dll function returns a pointer, so we have int(4). In most cases it will be a pointer to some structure.

And the next task is to pull data from this structure. We know the size of the structure, so we can first translate this pointer to a pointer to a char array.

Here's a question - how to do this reassignment? How to cheat? Maybe through an intermediate dll function, in which to pass the pointer, and it will return this char array?
Well, and then this char array by simple = transfer to our structure.

Here is a variant of such a function in dll

void Convert(char *_in, char *_out) { _out=_in; }

and it is called from mql like this

// e.g. the api function returned a pointer to a data structure
int ptr=ФункцияИзАпи(); // pointer to ДанныеИзАпи

struct ДанныеИзАпи
{
  // data structure from api 16 bytes
};

struct refData
{
 char byte[16]; // image of the same structure, also = 16 bytes 
};

refData ref;

Convert(ptr, ref.byte); // translated the pointer to the array

ДанныеИзАпи data=ref; // fill the fields of the structure by simple copying

PS
Although I came up with an idea with memcpy. It also copies by pointer. I should try it now.
 
yes. memcpy works ! and in conjunction with strcpy it is possible to process even strings correctly,

so it may work directly!!!!
 

Another stone in the MK's favour.

Why such fiddling?

Can their own programmes really spoil the face?

 
Urain:

Actually, this is not a stone against you, the message was to MQ developers, the problem is old and its solution is obviously in demand.

All in all, everything is good, the problem has been solved, the bible for MQL5 without using a self-written DLL has been successfully made and tested.

I have already sent it for publication :)

 
her.human:

Another stone in the MK's favour.

Why such fiddling?

Can their own programmes really spoil the face?

MQ5/EX5 programmes are very easily distributed and without strict security control can cause irreparable damage to users.

That's why the MQL5 application language is created protected, without the ability to call dangerous functions and working in its own sandbox. There is integration with DLL libraries to extend the functionality.

 
Renat:

MQ5/EX5 programmes are very easy to distribute and without strict security control can cause irreparable damage to users.

That is why the MQL5 application language is designed to be protected, without the ability to call dangerous functions and working in its own sandbox. There is integration with DLL libraries to extend the functionality.

What about the Market?

Or will win dlls be allowed in the market?

In general, I know the answer, that's why I suggested to make this implementation in the MQL5 standard.