Boost logo

Boost Users :

Subject: Re: [Boost-users] [interprocess] Container
From: Moritz (mokoman_at_[hidden])
Date: 2009-07-09 15:24:38


> is there a possibility to put something like this into the shared_memory?
>
> class A
> {
> int a;
> double d;
> // ...
> boost::interprocess string s;
> }

I need to save classes in the managed_shared_memory that contain strings
and vectors and all that stuff.
So the general way to put a string into the shared_mem is like this:

typedef boost::interprocess::allocator<char,
boost::interprocess::managed_shared_memory::segment_manager> CharAllocator;
typedef boost::interprocess::basic_string<char, std::char_traits<char>,
CharAllocator> string;

string *s = managed_shm.find_or_construct<string>("String")("bla",
managed_shm.get_segment_manager());

So I now want to save a class that contains a string. Therefore I wanted
  to use a class like this:

class A
{
public:
A(boost::interprocess::managed_shared_memory::segment_manager *seg)
  : calloc(seg), s(calloc)
{};

CharAllocator calloc;
string s;
}

and then I wanted to do something like this:
A *a =
managed_shm.find_or_construct<A>("name")(managed_shm.get_segment_manager());
//to save in the shared_mem

BUT for some reason the = operator of allocator is private. The first
question is now if there is a general way to save a class like this in
the shared_memory.

And if so, the second question is how I can create an instance of this
class that does _not_ allocate memory from the shared_memory (for
purposes of the process that writes to the shared_mem). To write to the
shared_mem I just want to say:

(*a) = anotherA;

where anotherA is an instance from A that does not allocate memory from
the shared memory.

I hope it is not too confusing.

Thanks in advance
Best regards,
Moritz


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