const char* in shared memory object

Hi all!
I'm a newbie with boost and I'm struggling with objects in shared memory.
The following struct is given:
struct MyType{
int id;
const char* name;
const char* rep;
MyType(){};
MyType(MyType* const& type){
id = type->id;
name = type->name;
rep = type->rep;
};
Objects of MyType should be shared between processes in shared memory. I
have no problem to
put and extract the objects from shared space. But I'm struggling with the
const char* pointers.
I know that pointers are not allowed in shared memory, thats why I tried to
realize with boost string by doing the following:
typedef
boost::interprocess::allocator

Sabine B
I'm a newbie with boost and I'm struggling with objects in shared memory. [...]
Objects of MyType should be shared between processes in shared memory. I have no problem to put and extract the objects from shared space. But I'm struggling with the const char* pointers.
Is there a reason that you are prefering 'const char *' over C++ strings (either std::string or, more to the point, boost::interprocess::string? The latter are explicitly designed to live in shared memory, while std::string makes assumptions which break when shared across different process address spaces. We just recently had a very closely related thread on this topic; it might be helpful to you: http://thread.gmane.org/gmane.comp.lib.boost.user/72140 I included some working code as well as specific links into the Boost.Interprocess documentation. Hope this helps! Best regards, Anthony Foiani

Hi Anthony!
This helped! I could solve my problem!
Thank you very much!!!
Best regards,
Sabine
On Fri, Jan 13, 2012 at 5:50 AM, Anthony Foiani
Sabine B
writes: I'm a newbie with boost and I'm struggling with objects in shared memory. [...]
Objects of MyType should be shared between processes in shared memory. I have no problem to put and extract the objects from shared space. But I'm struggling with the const char* pointers.
Is there a reason that you are prefering 'const char *' over C++ strings (either std::string or, more to the point, boost::interprocess::string? The latter are explicitly designed to live in shared memory, while std::string makes assumptions which break when shared across different process address spaces.
We just recently had a very closely related thread on this topic; it might be helpful to you:
http://thread.gmane.org/gmane.comp.lib.boost.user/72140
I included some working code as well as specific links into the Boost.Interprocess documentation.
Hope this helps!
Best regards, Anthony Foiani _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Anthony Foiani
-
Sabine B