Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29386 Discussions

Pass memory address to other programs

psantos
Beginner
1,032 Views
Hi to everybody. I am currently working on two different programs. The main program calls the other .exe program that computes some things and export data to .txt files. When the second program ends the main program continues and read data from the .txt files. I'm wondering if there's any possibility of the main program access directly the memory address of where data computed from the second programs are, instead of reading it from .txt files. Sometimes the main programs spent a lot a time reading and writing .txt files! Note that main program and the other program are separated .exe files.

I apreciate all the help you can provide to me!

Gratefully,

Pedro Santos
0 Kudos
1 Solution
Steven_L_Intel1
Employee
1,032 Views
The different EXEs are in different address spaces, so you can't just pass the address. But you can share data between two programs through a DLL - see the provided sample DLL\DLL_Shared_Data for an example.

View solution in original post

0 Kudos
6 Replies
Steven_L_Intel1
Employee
1,033 Views
The different EXEs are in different address spaces, so you can't just pass the address. But you can share data between two programs through a DLL - see the provided sample DLL\DLL_Shared_Data for an example.
0 Kudos
psantos
Beginner
1,032 Views
Thank you very much for the answer Steve. I explored the sample program and I found that it does exactly what I need.

Gratefully,

Pedro Santos
0 Kudos
psantos
Beginner
1,032 Views
Hello Steve. I'm trying to use the dll to share data between my two programs and I almost achieved what I need. Despite of this, I'm having trouble sharing allocatable arrays because I can't initialize them to a non-zero value before they are allocated. Because of this no data is shared between programs thought this allocatable arrays. I also tried static arrays (example A(100)) and they worked fine. Is there any way to use allocatable array or I will be forced to change to static arrays? I appreciate all the help you can gave to me.

Gratefully,

Pedro Santos
0 Kudos
anthonyrichards
New Contributor III
1,032 Views
Why not just combine the two programs and use module variables to store shared data? You might also keep the output text files as a check on the data you are sharing.
0 Kudos
Steven_L_Intel1
Employee
1,032 Views
You can't share allocatable arrays in this fashion. The static arrays work because the memory is allocated in the DLL and each of the executables map to it. The closest thing you can accomplish with dynamic allocation is to use the file mapping functions of Windows, but you would then have to use pointers to reference the data and this is somewhat complicated to set up.

You might also consider using other forms of interprocess communication, such as pipes, or even reconsider whether separate executables are really appropriate here. Perhaps a multithreaded approach would be suitable?
0 Kudos
psantos
Beginner
1,032 Views
Thank you for the reply. Yes I need to keep separated executables. I will investigate deeper your suggestions but it's almost certain that I will use the dll module to share data using static allocation. This method is very easy to implement and is capable of a significant speed up. I run a few test and I became very interested in the speed up that I achieved. Read and Write to files is really a time cost operation. Thank you Steve for the precious help you gave to me (one more time). This forum is really helpful.

Gratefully,

Pedro Santos
0 Kudos
Reply