And how did you create this 'mem' with std::vector inside?
And how did you create this 'mem' with std::vector inside?
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
QVector (and other C++ objects) contain pointers inside. These pointers are pointers inside the creating process's memory. If you put that in shared memory, the other process's accessing it will try that address - which is invalid (hopefully) for them.
You need either special containers or at least allocators to put containers into shared memory. (See e.g. Boost Interprocess)
Anything without pointers can be used (so no QString, std::string either, for example).
HTH
MattPhillips (9th December 2009)
Caduel,
Thanks, that was exactly it. Just to convince myself I created two structs,
Qt Code:
struct A { char ch; int i; double d; }; struct B { char ch; int* i; double d; };To copy to clipboard, switch view to plain text mode
and indeed, A worked fine but B did not. Thanks again. Thanks too faldzip for your consideration.
Matt
Hey Matts,
did you find a way to share pointers to variables ( i.e. struct B ) ?
thanks,
Michael
don't exaggerate. probably there are some containers that allow you to share whole objects. just search.
Hi,
It looks like the Boost IPC library has smart pointers which can be used within a shared memory block.
http://www.boost.org/doc/libs/1_38_0....qg_offset_ptr
But no dice with standard containers, in STL or I presume Qt as well.
Matt
Bookmarks