PDA

View Full Version : Can I create multiple data-structures for single QSharedMemory



rawfool
8th May 2013, 07:41
I need to share multiple data-structures across from my QSharedMemory. I tried "Shared Memory" example, which loads a image from file & from shared memory.
I need to share multiple structures across QSharedMemory for non-Qt application. If not, is it possible to avoid reading a all the sharedmemory chunk every time when I poll for a change ? Is there any example available depicting this scenario ? Kindly help me. Thank you.

Santosh Reddy
8th May 2013, 11:09
I need to share multiple data-structures across from my QSharedMemory. I tried "Shared Memory" example, which loads a image from file & from shared memory.
I need to share multiple structures across QSharedMemory for non-Qt application.
QSharedMemory is just a chunk of memory, one can store multiple data structures in it.


If not, is it possible to avoid reading a all the sharedmemory chunk every time when I poll for a change ?
Yes it is always upto programmer to read only the required part of memory, but note that one can get the only one handle to the memory.

I hope you have read this warning about using QSharedMemory between Qt and non-Qt Application, pay attention to the bold text.

QSharedMemory changes the key in a Qt-specific way, unless otherwise specified. Interoperation with non-Qt applications is achieved by first creating a default shared memory with QSharedMemory() and then setting a native key with setNativeKey(). When using native keys, shared memory is not protected against multiple accesses on it (e.g. unable to lock()) and a user-defined mechanism should be used to achieve a such protection.