小编Max*_*Max的帖子

如何创建进程间容器的boost进程间向量?

我喜欢创建一个包含进程间容器的类的boost进程间向量.以下代码一直有效,直到resize函数调用,当然因为我的类没有默认构造函数.我该如何解决这个问题?该示例基于容器的boost 容器示例

谢谢马库斯

#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/containers/map.hpp>
#include <boost/interprocess/containers/vector.hpp>
#include <boost/interprocess/containers/string.hpp>

using namespace boost::interprocess;

//Typedefs of allocators and containers
typedef managed_shared_memory::segment_manager                       segment_manager_t;
typedef allocator<void, segment_manager_t>                           void_allocator;
typedef allocator<int, segment_manager_t>                            int_allocator;
typedef vector<int, int_allocator>                                   int_vector;
typedef allocator<char, segment_manager_t>                           char_allocator;
typedef basic_string<char, std::char_traits<char>, char_allocator>   char_string;

class complex_data
{
public:
   int               id_;
   char_string       char_string_;
   int_vector int_vector_;

   //Since void_allocator is convertible to any other allocator<T>, we can simplify
   //the initialization taking just one allocator for all inner containers.
   complex_data(const …
Run Code Online (Sandbox Code Playgroud)

containers boost vector interprocess allocator

3
推荐指数
1
解决办法
1816
查看次数

标签 统计

allocator ×1

boost ×1

containers ×1

interprocess ×1

vector ×1