Sign in to follow this  
Xeile

Shared Memory & File Mapping

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this