QSharedMemory, Read / Write and Read Only.
-
I'm looking at using the QSharedMemory and I've downloaded the example application at:
https://doc.qt.io/qt-5/qtcore-ipc-sharedmemory-example.htmlI want to create an area of shared memory that an application is able to Read and Write, and then only allow other applications Read only.
I can see the class documentation at:
https://doc.qt.io/qt-5/qsharedmemory.htmlAre there any good tutorials on how to achieve what I want to do?
-
@Bonnie , kind of, the difference is, I'm designing and writing an application where the application thats launched can be configured to launch other modules. Each module will create manage its own shared memory area, the shared memory will be read/write to the module and read only to the application that launched it.
The main application will use the modules to provide additional services, the idea is that this system will be expandable without code changes to allow new modules and additional functionality.
-
@SPlatten said in QSharedMemory, Read / Write and Read Only.:
is there an example of this ?
An example on how to pass an enum to QSharedMemory::attach()??
-
As my understanding, the OP want the shared memory to only be ReadWrite to the application which create it, but ReadOnly to other applications which use this shared memory.
So I thought he can't control all the applications. (Otherwise he can just tell these applications don't write.)
But QSharedMemory::AccessMode is controlled by the application which calls QSharedMemory::attach().
Let's say if I know the OP's shared memory key, then I can write an application to attach it by QSharedMemory::ReadWrite and overwrite his shared memory.
So I thought that's not he wants.
@SPlatten Is my understanding right? -
@SPlatten Do you know about the existence of QRemoteObjects ?
It may be more suitable for your project -
@SPlatten said in QSharedMemory, Read / Write and Read Only.:
@JonB , I want to support all platforms which is why I'm going to implement my own solution.
From what I have seen reading around (not very thorough) I don't think you can do this, certainly not on all platforms. It may be possible to export it read-only to child processes, but I don't see that for non-related processes? If it's not doable at the OS level, then
QSharedMemory
isn't going to be able to do it, for unrelated/non-Qt processes?When people start talking about, say,
QRemoteObjects
, I think you should clarify whether the other processes you want to share with are under your control/even written in Qt?- Do you have any control over the other processes?
- Are these other processes run as sub-processes of your Qt process, or quite separately?
-
@JonB , I only want this solution for all processes in my solution, so for example the main process will create the framework for the memory map and then other 'modules' which provide additional functionality to the main process will add they're own additional memory maps. The idea being that each process that creates there own memory map has read and write access to the map, ever other process that is not the owner will have read only access.
For each memory map I will add flags to the front of the map which indicate when the memory has been updated.
-
@SPlatten
Then I think I would at least read the proposed solutuon in, say, https://stackoverflow.com/a/35003672/489865So one thing you can do is shm_open(..., O_RDWR) in the parent and set up a writable mapping for the parent before closing the handle, then shm_open(..., O_RDONLY) to get a read-only file handle which you will pass to the children
I do not know how
QSharedMemory
operates, but if it indeed leverages thisshm_...
approach it may be relevant.I will keep quiet now, as I know no more than this....