Author |
Message |
DIIST

|
Posted: Sun Jun 03, 2007 10:23 am Post subject: Sharing Memory Between Two Programs |
|
|
Does any one out there know how you can share the same variable between two different programs written in two different languages. Basically what i was thinking was writing the address and size of the variable created in program1 to a file. Then reading it from program 2 and setting a pointer to the memory address. The problem is my environment keeps crashing becasue the OS wont let me do this. Is there a way i can set a variable in C so that i can share the variable in another program (or do i have to do something in assembly ). |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Skynet
|
Posted: Sun Jun 03, 2007 2:22 pm Post subject: Re: Sharing Memory Between Two Programs |
|
|
What platform are you writing this for? |
|
|
|
|
 |
DIIST

|
Posted: Sun Jun 03, 2007 2:40 pm Post subject: Re: Sharing Memory Between Two Programs |
|
|
I'm writing it for Windows XP, and I'm hoping for it to run on other windows platforms as well(except maybe vista). If your referring to hardware then probably an x86 machine. |
|
|
|
|
 |
md

|
Posted: Sun Jun 03, 2007 4:23 pm Post subject: RE:Sharing Memory Between Two Programs |
|
|
Yes it's possible; but not like you think. You can share pages of ram between programs, using some windows APIs. But you won't necessarily have them mapped to the same address range.
Also, making it work between 2k-vista should be easy as they all use similar underlying APIs. Any OS before 2k is pretty much useless and not worth even attempting to support.
And no, I do not know the API required nor anything specific to windows. |
|
|
|
|
 |
Skynet
|
Posted: Sun Jun 03, 2007 10:22 pm Post subject: Re: Sharing Memory Between Two Programs |
|
|
Sorry, can't help.
IIRC, in UNIX you provide an ID and a structure to a function call, which then returns a pointer. The ID has to be known to both programs, and the struct is your own definition of what you'll be storing there. (You may be able to provide something as simple as a char array, but I've never tried that) Windows may work the same way, but I don't know the OS call. |
|
|
|
|
 |
DIIST

|
Posted: Mon Jun 04, 2007 5:59 am Post subject: Re: Sharing Memory Between Two Programs |
|
|
Thanks any way, ill look into how its done on UNIX. Who knows, it might be the same for both OS.  |
|
|
|
|
 |
Mazer

|
Posted: Mon Jun 04, 2007 9:21 am Post subject: RE:Sharing Memory Between Two Programs |
|
|
What about sharing the value of the variable itself in the file? Or using sockets? |
|
|
|
|
 |
wtd
|
Posted: Mon Jun 04, 2007 11:28 am Post subject: RE:Sharing Memory Between Two Programs |
|
|
Your best bet is to have a server-client relationship going on, with the data that needs "sharing" provided by a server program with which the client applications communicate. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
DIIST

|
Posted: Mon Jun 04, 2007 5:05 pm Post subject: Re: RE:Sharing Memory Between Two Programs |
|
|
Mazer @ June 4th 2007 wrote: What about sharing the value of the variable itself in the file? Or using sockets? That was how i originally planed to communicate between the two programs however I figured that sharing memory would be better and decided to give it a shot. It seemed like a simple idea at first. If it keeps dragging on like this might as well switch back to something simpler like files or using sockets as a way of communication.  |
|
|
|
|
 |
Skynet
|
Posted: Mon Jun 04, 2007 6:38 pm Post subject: Re: RE:Sharing Memory Between Two Programs |
|
|
DIIST @ Mon Jun 04, 2007 5:05 pm wrote: That was how i originally planed to communicate between the two programs however I figured that sharing memory would be better and decided to give it a shot. It seemed like a simple idea at first. If it keeps dragging on like this might as well switch back to something simpler like files or using sockets as a way of communication. 
It really is easier, IMHO - you just need to find the right system call- something about "IPC" or just plain "shared memory". MSDN should have it. |
|
|
|
|
 |
md

|
Posted: Mon Jun 04, 2007 10:55 pm Post subject: RE:Sharing Memory Between Two Programs |
|
|
Files aren't a very good way of sharing data between apps. Pipes aren't bad; as they look just like files but are made for transfering data. Sockets are quite good because if you do it right it's easy to go from local sockets to networked sockets if you need to.
Shared memory usually isn't worth it unless you're doing threading models in a process-based OS. |
|
|
|
|
 |
|