Boost logo

Boost Users :

Subject: Re: [Boost-users] [interprocess] Container
From: Moritz (mokoman_at_[hidden])
Date: 2009-07-10 05:27:06


I tried a lot of things and it all comes down to the question below.
First I'll give an overview about what I want to do.

First some typedefs and then the class that should be written to the
shared_memory:

typedef boost::interprocess::managed_shared_memory::segment_manager
                             segment_manager_t;
typedef boost::interprocess::allocator<void, segment_manager_t>
                             void_allocator;
typedef boost::interprocess::allocator<char, segment_manager_t>
                             char_allocator;
typedef boost::interprocess::basic_string<char, std::char_traits<char>,
char_allocator> char_string;

class A
{
   A(const void_allocator &void_alloc);
    : str("", void_alloc)
   {};

char_string str;
//... other datatypes ...
};

const void_allocator * _void_alloc = _managed_shm->get_segment_manager();

ObjectType * pointer;

One object of class A is now written to shared_mem via:

template<typename ObjectType>
void createObjWithAllocator(ObjectType & obj)
{
pointer =
_managed_shm->construct<ObjectType>(boost::interprocess::unique_instance)(*_void_alloc);
};

The real communication is something like this. And here is the real problem:

template <typename ObjectType>
void write_object(ObjectType & data)
{
(*pointer) = data;
};

The problem now is that I cannot instantiate an object of class A
without an Allocator void_allocator. So the final question of all my
posts before is, if (and how) I can create an void_allocator that
allocates memory from the heap and not from the shared_mem that fits the
declaration of void_allocator.

Any hints?

Thanks in advance
Best regards,
Mortz


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