Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transfer array between 2 apps

Status
Not open for further replies.

dave755

IS-IT--Management
May 3, 2001
69
US
I have two closely coupled C++ applications running on the same PC (under Windows 2000). App1 computes an array of about 300 doubles, which must be used by App2. There is no specific need for App1 to take any action based on anything from App2.

What is the best way for App1 to give the data to App2?
Dave Gee
 
>> What is the best way

In order to even guess at that would require more information.

Perhaps you just need to write the array to a file and have the other app read it.

Your question is like telling someone you need them to dig a ditch and thats it. Without more information they don't even know where to start digging.

-pete
 
Always happy to supply more detail...

In the absence of a better way, the file-write, file-read method will work, but I am concerned about performance. I would like to do a memory-only transfer.

App1 is reading a sensor array and manipulating actuators based on the sensors. It is entirely self-contained and has no user interface to speak of. App2 provides machine operators with a view of what is happening with the control algorithm. App2 may or may not be running at any point in time.

As part of its periodic evaluation of the sensors, App1 computes an array of about 300 values, which are stored internally as type "double". This computation is repeated every 5 to 50 seconds (depending on a bunch of machine parameters). I have been assigned to add a feature to App2 such that these values are displayed on a graph.

Obviously, in order to graph the data, App2 has to come into possession of the data. Hence the question.

It appears that a simple Windows message can be used to send a pointer in the LPARAM, but there are issues with respect to process boundaries and GPF's. What I really want to know is how to have App1 allocate & populate an array for App2 to use. Dave Gee
 
Well there is the old “ReadProcessMemory() API that was just discussed in the past few weeks but I don’t recommend it.

COM could be used but that seems like overkill for your solution.

I think either sockets or named pipes. If you have never done any socket based development I would suggest using named pipes. Start by looking at the CreateNamedPipe API and from there you will see the rest. There is also a real old sample application of a chat program using named pipes.

Good luck
-pete
 
You can use clipboard too.
Also you can make GlobalAlloc in app1,
find the main window of app2, send handle of
memory to the window of app2 in the user message
and get information in app2 using GlobalLock.
 
You can refer examples given in msdn for Memory Mapping of files too..this example is given in MFC as well as for SDK where interprocess communication is concerned
 
Various methods have various benefits.

Memory mapped files is by far the fastest way to shuffle large amount of data between apps.

If performance is an issue - use it.
 
You could use some sort of sockets implementation, which is also helpful if you decide to move one program to a different machine.
 
Thank you, everyone. Your help has saved me hours of crawling around in MSDN.

I have successfully implemented direct transfer using the Clipboard, which is a more formalized variant of passing global memory handles. Using the clipboard saves me from having to free the memory, since the system does it automatically.

The relevant docs can be found at this link:

Dave Dave Gee
 
>> but I am concerned about performance.

If you did both Clipboard and Named pipes and compare performance.... I think i know what you will find. ;-)

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top