2011-12-15 69 views
2

这是迄今为止我所拥有的。但是这甚至没有编译。我该怎么做才能使它工作?在共享内存中的增强地图内插入增强矢量

typedef allocator<int, managed_shared_memory::segment_manager> vecAllocator; 
typedef vector<int, vecAllocator> vec; 
typedef std::pair<const int, vec> ValueType; 
typedef allocator<ValueType, managed_shared_memory::segment_manager> ShmemAllocator; 
typedef multimap<int, vec, std::less<int>, ShmemAllocator> MyMap; 

ShmemAllocator alloc_inst (segment.get_segment_manager()); 
vecAllocator vectorallocator (segment.get_segment_manager()); 

MyMap *mymap = segment.construct<MyMap>("MyMap")(std::less<int>(),alloc_inst); 
vec *myvec = segment.construct<vec>("myvec")(std::less<int>(), vectorallocator); 
myvec->push_back(10); 

我现在该怎么做才能将此矢量插入地图? 这是一件事,我试图

mymap->insert(std::pair<const int, vec>(i, myvec)); 

,但似乎没有工作。我知道在共享内存中创建一个指向矢量的指针并不是正确的选择。我需要为它创建一个对象,如果我要将它插入到地图中。但如何做到这一点或至少如何将这些东西纳入共享内存?

由g ++抛出的错误是:

sharedMap.cpp:46: no matching function for call to ‘std::pair<const int, boost::container::vector<int, boost::interprocess::allocator<int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> > > >::pair(int&, main()::vec*&)’ 
    /usr/include/c++/4.2.1/bits/stl_pair.h:84: note: candidates are: std::pair<_T1, _T2>::pair(const _T1&, const _T2&) [with _T1 = const int, _T2 = boost::container::vector<int, boost::interprocess::allocator<int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> > >] 
    /usr/include/c++/4.2.1/bits/stl_pair.h:80: note:     std::pair<_T1, _T2>::pair() [with _T1 = const int, _T2 = boost::container::vector<int, boost::interprocess::allocator<int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> > >] 
    /usr/include/c++/4.2.1/bits/stl_pair.h:69: note:     std::pair<const int, boost::container::vector<int, boost::interprocess::allocator<int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> > > >::pair(const std::pair<const int, boost::container::vector<int, boost::interprocess::allocator<int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> > > >&) 
    /usr/local/include/boost/preprocessor/iteration/detail/local.hpp: In member function ‘void boost::interprocess::detail::Ctor2Arg<T, is_iterator, P0, P1>::construct(void*, boost::interprocess::detail::false_) [with T = boost::container::vector<int, boost::interprocess::allocator<int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> > >, bool is_iterator = false, P0 = std::less<int>, P1 = boost::interprocess::allocator<int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> >]’: 
    /usr/local/include/boost/preprocessor/iteration/detail/local.hpp:40: instantiated from ‘void boost::interprocess::detail::Ctor2Arg<T, is_iterator, P0, P1>::construct_n(void*, size_t, size_t&) [with T = boost::container::vector<int, boost::interprocess::allocator<int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> > >, bool is_iterator = false, P0 = std::less<int>, P1 = boost::interprocess::allocator<int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> >]’ 
    sharedMap.cpp:54: instantiated from here 
    /usr/local/include/boost/preprocessor/iteration/detail/local.hpp:40: error: no matching function for call to ‘boost::container::vector<int, boost::interprocess::allocator<int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> > >::vector(const std::less<int>&, const boost::interprocess::allocator<int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> >&)’ 
    /usr/local/include/boost/interprocess/containers/container/vector.hpp:474: note: candidates are: boost::container::vector<T, A>::vector(boost::interprocess::rv<boost::container::vector<T, A> >&) [with T = int, A = boost::interprocess::allocator<int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> >] 
    /usr/local/include/boost/interprocess/containers/container/vector.hpp:465: note:     boost::container::vector<T, A>::vector(const boost::container::vector<T, A>&) [with T = int, A = boost::interprocess::allocator<int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> >] 
    /usr/local/include/boost/interprocess/containers/container/vector.hpp:456: note:     boost::container::vector<T, A>::vector(typename A::size_type, const T&, const A&) [with T = int, A = boost::interprocess::allocator<int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> >] 
    /usr/local/include/boost/interprocess/containers/container/vector.hpp:445: note:     boost::container::vector<T, A>::vector(typename A::size_type) [with T = int, A = boost::interprocess::allocator<int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> >] 
    /usr/local/include/boost/interprocess/containers/container/vector.hpp:434: note:     boost::container::vector<T, A>::vector(const A&) [with T = int, A = boost::interprocess::allocator<int, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> >] 

线54是在主返回最后一行(其返回)

线46是mymap->插入线。

+0

“但似乎没有工作” - 发生了什么? – sehe 2011-12-15 09:46:47

+0

我想你应该创建一对'std :: pair (i,* myvec)`。 – yasouser 2011-12-15 11:41:02

回答

1

的问题是在这里:

vec *myvec = segment.construct<vec>("myvec")(std::less<int>(), vectorallocator);

有传递std::less<int>例如没有用。试试这个:

vec *myvec = segment.construct<vec>("myvec")(vectorallocator);