|
Boost Users : |
Subject: [Boost-users] const char* in shared memory object
From: Sabine B (sabine565_at_[hidden])
Date: 2012-01-12 05:04:03
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<char,boost::interprocess::managed_shared_memory::segment_manager>
CharAllocator;
typedef boost::interprocess::basic_string<char, std::char_traits<char>,
CharAllocator> MyString;
boost::interprocess::managed_shared_memory
segment(boost::interprocess::open_only, "MySharedMemory");
CharAllocator charallocator(segment.get_segment_manager());
struct MyType{
int id;
MyString name;
MyString rep;
MyType(){};
MyType(MyType* const& type){
id = type->id;
name = type->name;
rep = type->rep;
};
But this is not working because the segment and charallocator are not
recognized in the struct and if I put
boost::interprocess::managed_shared_memory
segment(boost::interprocess::open_only, "MySharedMemory");
CharAllocator charallocator(segment.get_segment_manager());
In the struct I get compiler errors.
Could anybody help me how I can realize const char* in an object that
should be shared?
Please help me!
Thank you very much!
Best regards,
Sabine
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net