A tangle with shared memory
Recently I was thinking about inter-process communication and especially how to pass/ share data/ information between two running applications. The thing was, I wanted to check out inter-process communication interfaces and see if there was anything Qt provided that I could use.
My requirement is not finalized or anything. The rough idea is to have a channel of communication between two apps. Here my thoughts diverge a bit in that, I am yet not sure of the method of communication. There are two approaches:
1. The message system should be a message board where many processes post messages for each other and periodically access the boards to check out their messages.
2. The message system should be P2P. One process sends a message to another and that message (preferably named) makes other process do something like maybe send an acknowledgement.
Now after digging through the various approaches, I have found out that for scenario 1, I could use shared memory. For scenario 2 I could use socket communication.
So just to check out the shared memory stuff I went ahead and dug up Qt's provided example.
The source has one class that contains that example as class SharedMemoryEx. It works as advised. I came across a limitation though. E.g. If first process runs, posts a message, and quits, then in this case the memory is released (at least in Windows case, where I tested the said code), and the message gets lost.
Well, I think we can engineer around this. Or maybe just use files for this purpose.
Although while looking around I found an interesting suggestion by someone about making a single instance application using shared memory.
That's the second class SingleClass.
Comments
Post a Comment