Pass an array address between applications

Hi,

Firstly I would like to point out that I am new to C++.

I am writing an expert advisor and indicator in MQL4 and a DLL in C++. The DLL will handle the heavy number crunching that I want to do.

My problem is that I want to find a way to access the same large array of double values in the expert advisor and the indicator that is created by the DLL. The job of the indicator is to simply display the computed values from the DLL on the chart.

I was thinking of trying to it in the following way and I would like to know if it is possible or if anyone thinks there is a better way.

The expert advisor will first call the DLL with and get it to create a large array of double values. I then want to convert the address of the array in the DLL to a string and pass this string back to the expert advisor which will in turn pass it to the indicator which will then pass it on to the DLL. The DLL called by the indicator will then convert the string to a pointer address so that the array can be used by the indicator.

Is anything like this possible?

Regards,

John



Let's step back a bit.
* What are you trying to accomplish, in general?
* If the DLL is the one that does the number crunching, why do other modules need access to its internal data structures?
* What's the use of exposing the address of the array? Will there be more than one of those big arrays of doubles?
Thanks for the reply,

MQL is used for writing charting programs and is a very limited implementation of C++.

The charting programs written run in an environment called MT4 which displays the charts.

Expert Advisor's are used for talking to the MT4 server and run in a separate thread to the MT4 charting interface but cannot plot particular lines on the chart that I need.

Indicators can plot the lines I need on the chart but unfortunately run in the same thread as the charting interface, when a fair bit of number crunching is done in an indicator this causes the charting interface to appear to hang which is very frustrating.

The hanging reason is why I want the expert advisor to call the DLL for the number crunching (in a separate thread) and to find some way of passing the address to the data so that I can get the indicator to plot that data.

Does this make sense?

John
@skiner36,

No, it's not clear enough to be followed.

You do not fashion the address of an array into a string for use as an address to data later. At most you involve a string for the display of an address, but that's a programmer's debugging tool from the 60's.

We need you to be clearer, a little more precise on the details.

You mention threads, but are not clear at processes. Based on the way you bring the DLL into the discussion it sounds like you have two PROCESSES. They are very different beasts.

There is no effort required to pass an address around various parts of code inside a single process that may be used by shared libraries (DLL's). The only reason I can think you'd have an issue to inquire about are

a) if the DLL allocates the memory or
b) if the DLL in question is in use by multiple processes.

Even if the DLL allocates the memory, it usually is managed such that there's very little issue - as long as we're talking about a single process. Threads in the process share the same memory space (with a thread local feature if you intentionally use it). At most you need synchronization and perhaps some attention to memory management (who deletes a shared resource), but beyond that there's no real work involved.

So I must assume you're asking about sharing memory among multiple processes.

The operating system is specifically design to prohibit that.

There is one exception, known as memory mapping. It is in the subject of inter-process communications, and with that technique you can open a window of memory shared among multiple processes (which almost always involves synchronization with something like named mutexes).

Is that making sense?






I have found a satisfactory way of solving my problem in MQL by using FileReadArray() and FileWriteArray().

I am able to write 2000000 records to a binary file in about 1 second. Reading is about the same amount of time.

Thanks everyone for your time

John
Topic archived. No new replies allowed.