Another problem : share the same variable by two exe

Started by
8 comments, last by SunDog 17 years, 1 month ago
Hi, I am currently trying to develop a pugin for a program. What I want to do is interface my plugin (which would be an executable) with another executable. I am planning to pass through an interface DLL. Here is the concept : class Interface{ public: shared variables pointers... }; I create an interface object in the first program, that put the shared variables in the interface. Then, I launch my plugin, but I need it to share the same Interface object... the problem is that an executable cannot take a pointer in parameter... or can it ?? Thanks
Advertisement
What you're looking for is called, aptly enough, "shared memory". It's very, very OS specific, so I suggest looking through a programming reference for your OS of choice. Google'ing will also probably get you what you want.
First, what language?

Second, you should use {code} and {source} blocks (use [] instead of {}) when you are posting code.

There are ways of sharing memory between different processes -- that is what you are describing that you want to do, I think. You can allocate them on shared memory pages. It is possible your language has tricks to help you do this.

On the other hand, there are often problems when you do this -- you have two different programs poking at the same set of bits in memory. Why do you want to solve this problem using multiple seperate executables? What kind of information are you looking to share?

OK, first I use Windows and C++.

I need to launch an executable because I want to create a window for opengl graphics. Actually, I don't know if I can create a graphical window from a dll. If so, I could just compile everything in the dll.

The main program is a physics simulator (Alices, from CORYS - www.corys.fr, one of the leading company for electrical power plant simulators). My plugin would be a 3d visualization of a power plant, interacting with cvariables calculated at each time step in the simulator. I just need to point to the variables I need to be able to animate in a 3d engine.


So you have a pluggable simulator, to which you add plugins in form of DLL.

But you want to write a plugin which does OpenGL visualization, something which the plugin system wasn't designed for. So you'll just make your own application which will communicate with your plugin.

Some questions here.
- What is the total number of variables here?
- How often are they updated?
- How much data is transferred.

Because if the total numbers are small, and variables are simple, using a simple socket will probably save you more headaches than any other aproach.

If numbers are large, then shared memory is a solution. While ideal performance-wise, it may sometimes prove to be too rigid, or even too fragile. This system also requires you to solve locking and memory access issues. You also need to keep track of changes to the memory and all other tiny details.

Pssing raw pointers all over the place is generally a bad idea, or can at least cause a lot of annoying bugs.

Quote:Original post by Dmnbp7ip
I need to launch an executable because I want to create a window for opengl graphics. Actually, I don't know if I can create a graphical window from a dll. If so, I could just compile everything in the dll.

Actually, I think you can. It's certainly worth trying it, since it sounds like it'll save you a lot of hassle if you can do it.

John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
Yeh, I realized the possibility to lauch an opengl vizualisation from a dll just when I wrote it... I do not know how to do it... yet. I am going to go into that direction.

See you in the OpenGL forum ;)

Thanks all


PS : just for information : in a power plant simulator, there can be thousands of equipments, each containing many variables... even if I will probably not represent everything, the number of variables used may not be neglictible.

PPS : the time step for the current simulator is 100ms, so It would be too long to use a time step visualizer. It must be asynchronous.
Pipes :-)
The volatile keyword will be your friend. Though, I'm not sure how to exchange pointers between programs like that.
william bubel
Actually I just realized a totally portable way to do it.

Its called a file :-)

This topic is closed to new replies.

Advertisement