2011-12-15 93 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);