Reputation: 1212
So, I'm trying to create a shared-memory segment in a C program, so I can for example write a simple character in it, and read that character from another C program.
I've been trying to use calloc()
and malloc()
but I do believe this only works for this program's own heap
.
Is there another function to do this same thing, but in the RAM
memory? Maybe through an hexadecimal value? Or am I wrong and these functions actually reserve memory visible to all processes?
Thanks in advance.
EDIT: -I'm using windows 8. -Language is not restricted to C, can be any other language.
Upvotes: 2
Views: 1573
Reputation: 51511
There are a number of Interprocess Communications you can choose, when you need to transfer data between isolated processes. Sharing a chunk of memory is typically implemented using file mapping objects.
Setting up a file mapping object requires the following sequence of API calls:
Using an existing file mapping object from another process requires the following calls:
Note that sharing memory through file mappings across processes requires synchronization between those processes. This topic is beyond the scope of this answer. The MSDN provides an introduction to synchronization.
Upvotes: 2
Reputation: 126536
There's no standard way of doing this. If you were working on Unix/Linux I would suggest looking at my shared memory malloc implementation, which does work on Cygwin on windows machines, but is really designed for Unix.
Upvotes: 0