QSharedMemory, update signal?
-
wrote on 22 Oct 2020, 09:32 last edited by SPlatten
I'm looking at using QSharedMemory, is there a signal that indicates when the memory has been updated so the other users of the shared resource can be notified of the update?
I have downloaded built and run the demo application which allows each instance to load an image, however I noticed that although the image changes on the dialog the image is loaded, the other instance is not notified of the update and no automatic update occurs until you do something on the other dialog to cause it to refresh.
-
I'm looking at using QSharedMemory, is there a signal that indicates when the memory has been updated so the other users of the shared resource can be notified of the update?
I have downloaded built and run the demo application which allows each instance to load an image, however I noticed that although the image changes on the dialog the image is loaded, the other instance is not notified of the update and no automatic update occurs until you do something on the other dialog to cause it to refresh.
@SPlatten If you use threads, use signals/slots. If you use several processes use IPC (Qt provides several possibilities).
-
@jsulm , thank you, I was hoping that since Qt provides the class QSharedMemory that this facility would already be available, seems kind of fundamental ?
I want to use this as a mechanism for IPC.
@SPlatten said in QSharedMemory, update signal?:
seems kind of fundamental ?
Notifying each time the shared memory is updated would result in A LOT of notifications and would decrease performance. How should Qt know when you did all your updates to send the notification?
And there is https://doc.qt.io/qt-5/qsharedmemory.html#lock which you have to call before writing. That means the other side can also call lock() and then wait on the semaphore until you call unlock(). This way the other side will know when writing was finished. -
@SPlatten said in QSharedMemory, update signal?:
seems kind of fundamental ?
Notifying each time the shared memory is updated would result in A LOT of notifications and would decrease performance. How should Qt know when you did all your updates to send the notification?
And there is https://doc.qt.io/qt-5/qsharedmemory.html#lock which you have to call before writing. That means the other side can also call lock() and then wait on the semaphore until you call unlock(). This way the other side will know when writing was finished.wrote on 22 Oct 2020, 09:52 last edited by SPlatten@jsulm , I agree, I was expecting there to be a function in the class QSharedMemory that you could call from any process that updates the shared memory to notify all users an update has occurred, which could take the form of something like:
notifyAll(offset, size);
Where the offset is the relative offsets in memory that is effected and the size if the size in bytes of the effected. I wasn't expecting it to be automatic when ever byte is changed.
As far as who to notify this could be a subscription type model where all processes using the shared memory are subscribers and notified of updates when a notify occurs.
-
@jsulm , I agree, I was expecting there to be a function in the class QSharedMemory that you could call from any process that updates the shared memory to notify all users an update has occurred, which could take the form of something like:
notifyAll(offset, size);
Where the offset is the relative offsets in memory that is effected and the size if the size in bytes of the effected. I wasn't expecting it to be automatic when ever byte is changed.
As far as who to notify this could be a subscription type model where all processes using the shared memory are subscribers and notified of updates when a notify occurs.
@SPlatten said in QSharedMemory, update signal?:
Where the offset is the relative offsets in memory that is effected and the size if the size in bytes of the effected
How can this be possible? Somebody would have to observe the shared memory all the time. And how can it decide when updating has finished?
-
@SPlatten said in QSharedMemory, update signal?:
Where the offset is the relative offsets in memory that is effected and the size if the size in bytes of the effected
How can this be possible? Somebody would have to observe the shared memory all the time. And how can it decide when updating has finished?
wrote on 22 Oct 2020, 10:01 last edited by@jsulm , what I mean is a memory map is created where the size and purpose of the map is clearly defined, the map would contain various data types but offset 0 would always point to the start of the map.
I've used exactly this system and design when sharing memory on a VME bus between industrial PLC's and VME PC's sharing the same rack space.
The map is documented and both sides know exactly what is where, when a change occurs the offset is relative to position 0.
There are various methods the applications can use to identify what the offsets mean but it could be that the offset if used correctly can be used to get a structure pointer to any position in the map.
-
J JonB referenced this topic on 25 Apr 2023, 20:11
1/8