Shared Memory & File Mapping

Started by
1 comment, last by Xeile 15 years, 5 months ago
Hey all, I am currently working on some small study project where I am experimenting with interprocess communication. The twist here is that one process is managed application written upon the .NET Framework 3.5 and the other process is a standard Win32 application. There are multiple communication methods and I decided to start experimenting with Shared Memory first. So far I was able to create a space of shared memory and let both application use it. However since the data that is stored is not static and variable in size, I want to be able resize my shared memory object (file mapping) to accommodate the data. How should I do this? Is there a way to resize the memory object in someway? I found suprisingly less information about this subject on how other people did this. Regards, Xeile
Advertisement
If the shared memory is used for IPC, then why does it need to change size? Wouldn't the data stored just be transient communication that's produced by one application and consumed by the other?

You can't really re-size shared memory. You have to devise some fancy protocol where one application tells the other application that it's going to re-size the memory buffer. The first application copies the shared memory to a temporary buffer, then both close their handles. Then the first application re-creates the shared memory, sends a ping to the other application, and copies the temporary buffer into the shared memory. Meanwhile the other application has been periodically waiting for the shared memory handle to come back "online" by attempting to open a handle to the shared memory (without creating it if it can), at which point it will send an acknowledgment to the ping waiting in the shared buffer. Then both applications can resume normal communication.

So while it's certainly not impossible, it is a process (no pun intended) that you could probably avoid is you re-evaluated why you needed to re-size the shared memory buffer in the first place.
Ah yes, that was what I feared. It does indeed come to the point if I am not better off enhancing my current communication system, to something more versatile.

Thanks for the help.

This topic is closed to new replies.

Advertisement