Boost interprocess unordered_map compilation - c++

I'm using boost 1.53 and GCC 4.1.2. I've tried to use boost unordered_map in some tests (documentation says, that it should work with shared memory), but i'm unable to compile my code. With interprocess::map instead of unordered everything is ok.
Typedefs:
typedef boost::interprocess::allocator<char, SegmentManager> CharAllocator;
typedef boost::interprocess::basic_string<char, std::char_traits<char>, CharAllocator> ShmString;
typedef ShmString HashKeyType;
//ComplexType is a wrapper for internal interprocess::map
typedef ComplexType HashMappedType;
typedef std::pair<const ShmString, ComplexType> HashValueType;
typedef boost::interprocess::allocator<HashValueType,
boost::interprocess::managed_shared_memory::segment_manager> HashMemAllocator;
typedef boost::unordered_map
< HashKeyType , HashMappedType
, boost::hash<HashKeyType> ,std::equal_to<HashKeyType>
, HashMemAllocator>
TestHashMap;
Allocation:
boost::interprocess::managed_shared_memory segment( boost::interprocess::open_or_create, "MySharedMemory", 65536);
thm_ = segment.construct<TestHashMap>("TestHashMap")
(3, boost::hash<ShmString>(), std::equal_to<ShmString>()
, segment.get_allocator<HashValueType>());
Usage:
boost::interprocess::managed_shared_memory segment( boost::interprocess::open_only, "MySharedMemory");
ShmString str("123.345", segment.get_allocator<ShmString>());
ComplexType th("MySharedMemory");
HashValueType value(str, th);
thm_->insert(value);
And here is some error output:
../boost/include/boost/unordered/detail/allocate.hpp: In instantiation of 'boost::unordered::detail::allocator_traits<boost::interprocess::allocator<boost::unordered::detail::ptr_node<std::pair<const boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> > >, TINHolderShared> >, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> > >::pointer_to_other<const boost::unordered::detail::ptr_node<std::pair<const boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> > >, TINHolderShared> > >':
../boost/include/boost/unordered/detail/allocate.hpp:527: instantiated from 'boost::unordered::detail::allocator_traits<boost::interprocess::allocator<boost::unordered::detail::ptr_node<std::pair<const boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> > >, TINHolderShared> >, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> > >'
../boost/include/boost/unordered/detail/unique.hpp:114: instantiated from 'boost::unordered::detail::pick_node<boost::interprocess::allocator<std::pair<const boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> > >, TINHolderShared>, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> >, std::pair<const boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> > >, TINHolderShared> >'
../boost/include/boost/unordered/detail/unique.hpp:158: instantiated from 'boost::unordered::detail::map<boost::interprocess::allocator<std::pair<const boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> > >, TINHolderShared>, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> >, boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> > >, TINHolderShared, boost::hash<boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> > > >, std::equal_to<boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> > > > >'
../boost/include/boost/unordered/unordered_map.hpp:59: instantiated from 'boost::unordered::unordered_map<boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> > >, TINHolderShared, boost::hash<boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> > > >, std::equal_to<boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> > > >, boost::interprocess::allocator<std::pair<const boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> > >, TINHolderShared>, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> > >'
utest/THUnitTests.cc:96: instantiated from here
../boost/include/boost/unordered/detail/allocate.hpp:523: error: ambiguous class template instantiation for 'struct boost::pointer_to_other<boost::interprocess::offset_ptr<boost::unordered::detail::ptr_node<std::pair<const boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> > >, TINHolderShared> >, long int, long unsigned int, 0u>, const boost::unordered::detail::ptr_node<std::pair<const boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0u>, 0ul>, boost::interprocess::iset_index> > >, TINHolderShared> > >'
../boost/include/boost/interprocess/offset_ptr.hpp:721: error: candidates are: struct boost::pointer_to_other<boost::interprocess::offset_ptr<T1, P1, O1, A1>, U>
../boost/include/boost/pointer_to_other.hpp:29: error: struct boost::pointer_to_other<Sp<T>, U>
../boost/include/boost/pointer_to_other.hpp:36: error: struct boost::pointer_to_other<Sp<T, T2>, U>
../boost/include/boost/pointer_to_other.hpp:43: error: struct boost::pointer_to_other<Sp<T, T2, T3>, U>
I'm not sure if the problem is in my code, or because of old compiler version.
If the problem is with compiler, then could it be fixed with newer version of boost? (i can't update my GCC). Or maybe there are some implementations of hash table, that are compatible with shared memory and with my compiler?

Here's a fixed up version.
I just tried to make it self contained according to the suggestive comments. And it works.
Hope it helps anyways:
Live On Coliru
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/containers/string.hpp>
#include <boost/interprocess/containers/map.hpp>
#include <boost/unordered_map.hpp>
namespace bip = boost::interprocess;
// ShmString is boost::interprocess::basic_string
typedef bip::allocator<char, bip::managed_shared_memory::segment_manager> CharAllocator;
typedef bip::basic_string<char, std::char_traits<char>, CharAllocator> ShmString;
typedef ShmString HashKeyType;
// ComplexType is a wrapper for internal interprocess::map
struct ComplexType {
typedef bip::allocator<std::pair<int const, int>, bip::managed_shared_memory::segment_manager> Alloc;
typedef bip::map<int, int, std::less<int>, Alloc> Map;
template <typename Alloc2>
ComplexType(std::string, Alloc2 const& alloc = {}) : map(alloc) {}
Map map;
};
typedef ComplexType HashMappedType;
typedef std::pair<const ShmString, ComplexType> HashValueType;
typedef bip::allocator<HashValueType, bip::managed_shared_memory::segment_manager> HashMemAllocator;
typedef boost::unordered_map<HashKeyType, HashMappedType, boost::hash<HashKeyType>, std::equal_to<HashKeyType>, HashMemAllocator>
TestHashMap;
int main()
{
// Allocation:
{
bip::managed_shared_memory segment(bip::open_or_create, "MySharedMemory", 65536);
auto thm_ = segment.construct<TestHashMap>("TestHashMap")(3, boost::hash<ShmString>(), std::equal_to<ShmString>(),
segment.get_allocator<HashValueType>());
}
// Usage:
bip::managed_shared_memory segment(bip::open_only, "MySharedMemory");
auto thm_ = segment.construct<TestHashMap>("TestHashMap")(3, boost::hash<ShmString>(), std::equal_to<ShmString>(), segment.get_allocator<HashValueType>());
ShmString str("123.345", segment.get_allocator<ShmString>());
ComplexType th("MySharedMemory", segment.get_segment_manager());
HashValueType value(str, th);
thm_->insert(value);
}

Related

Create boost::spsc queue in boost managed shared memory with a runtime size

Shared-memory IPC synchronization (lock-free)
My use case aligns very closely with what has been described in the above question. But I wanted to go a step further in creating the spsc queue dynamically with a user defined runtime size. I tried implementing it with the following code:
void create_shared_spsc_queue(size_t sz)
{
using char_alloc = boost::interprocess::allocator<char, boost::interprocess::managed_shared_memory::segment_manager>;
using shared_string = boost::interprocess::basic_string<char, std::char_traits<char>, char_alloc>;
using string_alloc = boost::interprocess::allocator<shared_string, boost::interprocess::managed_shared_memory::segment_manager>;
using ring_buffer_dynamic = boost::lockfree::spsc_queue<shared_string, boost::lockfree::allocator<string_alloc> >;
ring_buffer_dynamic *queue_dynamic_;
boost::interprocess::managed_shared_memory segment_(boost::interprocess::open_only, "MySharedMemroy");
string_alloc string_alloc_(segment_.get_segment_manager());
queue_dynamic_ = segment_.construct<ring_buffer_dynamic>(rbuff_name)(string_alloc_, sz);
}
But this throws compilation error:
/usr/include/boost/interprocess/detail/named_proxy.hpp:85:7: error: no matching function for call to ‘boost::lockfree::spsc_queue<boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char,
boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >,
boost::lockfree::allocator<boost::interprocess::allocator<boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0>, 0>,
boost::interprocess::iset_index> > >, boost::interprocess::segment_manager<char,
boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long int, long unsigned int, 0>, 0>, boost::interprocess::iset_index> > > >::spsc_queue(boost::interprocess::allocator<boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char,
boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >&, int)’
85 | { ::new((void*)mem, boost_container_new_t())T(boost::forward<Args>(get<IdxPack>(args_))...); }
I can understand its related to issue with allocators, but I can't seem to resolve it,
with my limited understanding of allocators. How can I implement this?
For posterity: I figured, I was calling the ctor of spsc_queue in wrong order of arguments. The following works:
queue_dynamic_ = segment_.construct<ring_buffer_dynamic>(rbuff_name)(sz, string_alloc_);
Source: https://www.boost.org/doc/libs/1_80_0/doc/html/boost/lockfree/spsc_queue.html

Boost interprocess flat_map operator[] compilation errors

I'm building some wrapper over the boost::interprocess::flat_map, the problem is, that i'm unable to use operator[] or at for some reason. When i'm using find or insert it compiles succesfully.
typedef boost::interprocess::managed_shared_memory::segment_manager SegmentManager;
typedef boost::interprocess::allocator<char, SegmentManager> CharAllocator;
typedef boost::interprocess::basic_string<char, std::char_traits<char>,
CharAllocator> ShmString;
typedef short KeyType;
typedef ShmString MappedType;
typedef std::pair<const short, ShmString> ValueType;
typedef boost::interprocess::allocator<ValueType,
boost::interprocess::managed_shared_memory::segment_manager> ShMemAlloc;
typedef boost::interprocess::flat_map<KeyType, MappedType,
std::less<short>, ShMemAlloc> ShMap;
class Wrapper {
public:
Wrapper(boost::interprocess::managed_shared_memory* memSeg) :
m_memSeg(memSeg) {
const ShMemAlloc initAlloc(m_memSeg->get_segment_manager());
m_storage = m_memSeg->construct
<ShMap> (boost::interprocess::anonymous_instance)
(std::less<KeyType>(), initAlloc);
ShmString str(initAlloc);
ValueType val(10, str);
m_storage->insert(val); //Ok
ShMap::iterator it = m_storage->find(5); //Ok
if(it != m_storage->end())
it->second = str;
(*m_storage)[5] = str; //Compilation error
};
~Wrapper();
protected:
boost::interprocess::managed_shared_memory* m_memSeg;
ShMap* m_storage;
};
It seem's like there is a problem with type deduction in allocator inside the operator[] call, but i have no idea how to use it correctly.
Here is the error report:
../boost/include/boost/container/string.hpp: In instantiation of 'boost::container::container_detail::basic_string_base<Allocator>::members_holder::members_holder() [with Allocator = boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >]':
../boost/include/boost/container/string.hpp:104:18: required from 'boost::container::container_detail::basic_string_base<Allocator>::basic_string_base() [with Allocator = boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >]'
../boost/include/boost/container/string.hpp:596:16: required from 'boost::container::basic_string<CharT, Traits, Allocator>::basic_string() [with CharT = char; Traits = std::char_traits<char>; Allocator = boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >]'
../boost/include/boost/container/detail/value_init.hpp:31:13: required from 'boost::container::container_detail::value_init<T>::value_init() [with T = boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >]'
../boost/include/boost/container/flat_map.hpp:846:52: required from 'boost::container::flat_map<Key, T, Compare, Allocator>::mapped_type& boost::container::flat_map<Key, T, Compare, Allocator>::priv_subscript(const key_type&) [with Key = short int; T = boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >; Compare = std::less<short int>; Allocator = boost::interprocess::allocator<std::pair<const short int, boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > > >, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >; boost::container::flat_map<Key, T, Compare, Allocator>::mapped_type = boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >; boost::container::flat_map<Key, T, Compare, Allocator>::key_type = short int]'
../boost/include/boost/container/flat_map.hpp:469:4: required from 'typename boost::enable_if_c<(((! boost::is_class<BOOST_MOVE_TEMPL_PARAM>::value) || (! boost::move_detail::is_rv<BOOST_MOVE_TEMPL_PARAM>::value)) && (! boost::is_same<Key, BOOST_MOVE_TEMPL_PARAM>::value)), T&>::type boost::container::flat_map<Key, T, Compare, Allocator>::operator[](const BOOST_MOVE_TEMPL_PARAM&) [with BOOST_MOVE_TEMPL_PARAM = int; Key = short int; T = boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >; Compare = std::less<short int>; Allocator = boost::interprocess::allocator<std::pair<const short int, boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > > >, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >; typename boost::enable_if_c<(((! boost::is_class<BOOST_MOVE_TEMPL_PARAM>::value) || (! boost::move_detail::is_rv<BOOST_MOVE_TEMPL_PARAM>::value)) && (! boost::is_same<Key, BOOST_MOVE_TEMPL_PARAM>::value)), T&>::type = boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >&]'
./include/.h:240:23: required from here
../boost/include/boost/container/string.hpp:218:22: error: no matching function for call to 'boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >::allocator()'
../boost/include/boost/container/string.hpp: In instantiation of 'boost::container::container_detail::basic_string_base<Allocator>::members_holder::members_holder() [with Allocator = boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >]':
../boost/include/boost/container/string.hpp:104:18: required from 'boost::container::container_detail::basic_string_base<Allocator>::basic_string_base() [with Allocator = boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >]'
../boost/include/boost/container/string.hpp:596:16: required from 'boost::container::basic_string<CharT, Traits, Allocator>::basic_string() [with CharT = char; Traits = std::char_traits<char>; Allocator = boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >]'
../boost/include/boost/container/detail/value_init.hpp:31:13: required from 'boost::container::container_detail::value_init<T>::value_init() [with T = boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >]'
../boost/include/boost/container/flat_map.hpp:846:52: required from 'boost::container::flat_map<Key, T, Compare, Allocator>::mapped_type& boost::container::flat_map<Key, T, Compare, Allocator>::priv_subscript(const key_type&) [with Key = short int; T = boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >; Compare = std::less<short int>; Allocator = boost::interprocess::allocator<std::pair<const short int, boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > > >, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >; boost::container::flat_map<Key, T, Compare, Allocator>::mapped_type = boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >; boost::container::flat_map<Key, T, Compare, Allocator>::key_type = short int]'
../boost/include/boost/container/flat_map.hpp:469:4: required from 'typename boost::enable_if_c<(((! boost::is_class<BOOST_MOVE_TEMPL_PARAM>::value) || (! boost::move_detail::is_rv<BOOST_MOVE_TEMPL_PARAM>::value)) && (! boost::is_same<Key, BOOST_MOVE_TEMPL_PARAM>::value)), T&>::type boost::container::flat_map<Key, T, Compare, Allocator>::operator[](const BOOST_MOVE_TEMPL_PARAM&) [with BOOST_MOVE_TEMPL_PARAM = int; Key = short int; T = boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >; Compare = std::less<short int>; Allocator = boost::interprocess::allocator<std::pair<const short int, boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > > >, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >; typename boost::enable_if_c<(((! boost::is_class<BOOST_MOVE_TEMPL_PARAM>::value) || (! boost::move_detail::is_rv<BOOST_MOVE_TEMPL_PARAM>::value)) && (! boost::is_same<Key, BOOST_MOVE_TEMPL_PARAM>::value)), T&>::type = boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> > >&]'
./include/.h:240:23: required from here
../boost/include/boost/container/string.hpp:218:22: error: no matching function for call to 'boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index> >::allocator()'
This took some digging. Your problem is that flat_map::operator[] requires the mapped type T to be default constructable because if the object does not exist it needs to be able to insert a default object at that location.
Your ShmString is not default constructable because it doesn't have a default constructable allocator (it has to use the shared memory allocator).
Thus it appears that in your case you will be unable to make use of operator[] and have to use other methods like insert, find, etc.

Trouble with boost::lockfree::queue in shared memory (boost 1.53, gcc 4.7.2 / clang 3.0-6ubuntu3)

I have a problem with placing boost::lockfree::queue<<T, fixed_sized<false>, ..>
in shared memory. I need it because I have to be able to insert more than 65535 messages into the queue, and fixed_sized queue is limited with 65535.
The following code works properly (but capacity<...> option implies fixed_sized<true>):
typedef boost::interprocess::allocator<
MessageT,
boost::interprocess::managed_shared_memory::segment_manager>
ShmemAllocator;
typedef boost::lockfree::queue<
MessageT,
boost::lockfree::capacity<65535>,
boost::lockfree::allocator<ShmemAllocator> >
Queue;
m_segment = new boost::interprocess::managed_shared_memory(
boost::interprocess::create_only, segmentName, size);
Queue* m_queue = m_segment->construct<Queue>(
queueName)(
m_segment->get_segment_manager());
...
m_queue->bounded_push(message);
The following code works properly too (but it doesn't use shared memory):
boost::lockfree::queue<MessageT> q;
....
q.bounded_push(message);
But when I try to combine it:
typedef boost::interprocess::allocator<
MessageT,
boost::interprocess::managed_shared_memory::segment_manager>
ShmemAllocator;
typedef boost::lockfree::queue<
MessageT,
boost::lockfree::allocator<ShmemAllocator> >
Queue;
m_segment = new boost::interprocess::managed_shared_memory(
boost::interprocess::create_only, segmentName, size);
Queue* m_queue = m_segment->construct<Queue>(
queueName)(
m_segment->get_segment_manager());
...
m_queue->bounded_push(message);
it fails to compile with the following log:
In file included from src/model/Queue.h:16:
In file included from /home/uppi/lib/include/boost/lockfree/queue.hpp:24:
/home/uppi/lib/include/boost/lockfree/detail/freelist.hpp:171:28: error: no viable conversion from 'pointer' (aka 'offset_ptr<boost::lockfree::queue<PacketMessage,
boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family,
boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, boost::parameter::void_, boost::parameter::void_>::node, long, unsigned long, 0UL>') to
'boost::lockfree::queue<PacketMessage, boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, boost::interprocess::segment_manager<char,
boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, boost::parameter::void_,
boost::parameter::void_>::node *'
return Alloc::allocate(1);
~~~~~~~~~~~~~~~~~
/home/uppi/lib/include/boost/lockfree/detail/freelist.hpp:157:20: note: in instantiation of function template specialization 'boost::lockfree::detail::freelist_stack<boost::lockfree::queue<PacketMessage,
boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family,
boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, boost::parameter::void_, boost::parameter::void_>::node,
boost::interprocess::allocator<boost::lockfree::queue<PacketMessage, boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, boost::interprocess::segment_manager<char,
boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, boost::parameter::void_,
boost::parameter::void_>::node, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned
long, 0>, 0>, iset_index> > >::allocate_impl<true>' requested here
return allocate_impl<Bounded>();
/home/uppi/lib/include/boost/lockfree/detail/freelist.hpp:89:20: note: in instantiation of function template specialization 'boost::lockfree::detail::freelist_stack<boost::lockfree::queue<PacketMessage,
boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family,
boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, boost::parameter::void_, boost::parameter::void_>::node,
boost::interprocess::allocator<boost::lockfree::queue<PacketMessage, boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, boost::interprocess::segment_manager<char,
boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, boost::parameter::void_,
boost::parameter::void_>::node, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned
long, 0>, 0>, iset_index> > >::allocate<true, true>' requested here
T * node = allocate<ThreadSafe, Bounded>();
/home/uppi/lib/include/boost/lockfree/queue.hpp:281:34: note: in instantiation of function template specialization 'boost::lockfree::detail::freelist_stack<boost::lockfree::queue<PacketMessage,
boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family,
boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, boost::parameter::void_, boost::parameter::void_>::node,
boost::interprocess::allocator<boost::lockfree::queue<PacketMessage, boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, boost::interprocess::segment_manager<char,
boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, boost::parameter::void_,
boost::parameter::void_>::node, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned
long, 0>, 0>, iset_index> > >::construct<true, true, PacketMessage, boost::lockfree::queue<PacketMessage, boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage,
boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >,
boost::parameter::void_, boost::parameter::void_>::node *>' requested here
node * n = pool.template construct<true, Bounded>(t, pool.null_handle());
/home/uppi/lib/include/boost/lockfree/queue.hpp:270:16: note: in instantiation of function template specialization 'boost::lockfree::queue<PacketMessage,
boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family,
boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >, boost::parameter::void_, boost::parameter::void_>::do_push<true>' requested here
return do_push<true>(t);
src/model/Queue.inl:4:18: note: in instantiation of member function 'boost::lockfree::queue<PacketMessage, boost::lockfree::allocator<boost::interprocess::allocator<PacketMessage,
boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void, long, unsigned long, 0>, 0>, iset_index> > >,
boost::parameter::void_, boost::parameter::void_>::bounded_push' requested here
return m_queue->bounded_push(message);
/home/uppi/lib/include/boost/interprocess/offset_ptr.hpp:450:4: note: candidate function
operator unspecified_bool_type() const
Please tell me what I'm missing
using boost::lockfree::queue or boost::lockfree::stack in shared memory is limited to 65535 elements, for compatibility reasons. if you have a single-producer, single-consumer use-case, you might want to use the boost::lockfree::spsc_queue. however this is also not dynamically-sized.
reason for this is limitation is 32bit compatibility. for 64bit platforms one might be able to adapt the boost.lockfree code to use 32bit instead of 16bit indices. but it would require some non-trivial changes to implement things correctly.

boost interprocess map with int and string

I have the following code that saves a map into shared memory using boost interprocess
using namespace boost::interprocess;
//Shared memory front-end that is able to construct objects
//associated with a c-string. Erase previous shared memory with the name
//to be used and create the memory segment at the specified address and initialize resources
shared_memory_object::remove("MySharedMemory");
try{
managed_shared_memory segment
(create_only
,"MySharedMemory" //segment name
,655360); //segment size in bytes
//Note that map<Key, MappedType>'s value_type is std::pair<const Key, MappedType>,
//so the allocator must allocate that pair.
typedef allocator<char, managed_shared_memory::segment_manager> CharAllocator;
typedef basic_string<char, std::char_traits<char> ,CharAllocator> MyShmString;
typedef allocator<MyShmString, managed_shared_memory::segment_manager> StringAllocator;
typedef int KeyType;
typedef std::pair<const int, StringAllocator> ValueType;
typedef StringAllocator MappedType;
typedef allocator<ValueType, managed_shared_memory::segment_manager> ShmemAllocator;
typedef map<KeyType, MappedType, std::less<KeyType>, ShmemAllocator> MyMap;
//Initialize the shared memory STL-compatible allocator
ShmemAllocator alloc_inst (segment.get_segment_manager());
CharAllocator charallocator (segment.get_segment_manager());
//Construct a shared memory map.
//Note that the first parameter is the comparison function,
//and the second one the allocator.
//This the same signature as std::map's constructor taking an allocator
MyMap *mymap =
segment.construct<MyMap>("MyMap") //object name
(std::less<int>() //first ctor parameter
,alloc_inst); //second ctor parameter
//Insert data in the map
MyShmString mystring(charallocator);
mystring = "this is my text";
for(int i = 0; i < 100; ++i){
//mymap[i] = mystring;
mymap->insert(std::pair<const int, MappedType>(i, mystring));
}
}
this code doesnt compile.. it throws the following error
no matching function for call to ‘std::pair<const int, boost::interprocess::allocator<boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> > >, 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()::MyShmString&)’
/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::interprocess::allocator<boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> > >, 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::interprocess::allocator<boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> > >, 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::interprocess::allocator<boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> > >, 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::interprocess::allocator<boost::container::basic_string<char, std::char_traits<char>, boost::interprocess::allocator<char, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> > >, boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family, boost::interprocess::offset_ptr<void>, 0ul>, boost::interprocess::iset_index> > >&)
the difference if
::pair(int&, main()::MyShmString&)
so i am guessing
mymap->insert(std::pair<const int, MappedType>(i, mystring));
is not the correct way to go.. so how should i insert into the map, if the error is there.. else what is the error?
Surely the value_type is:
typedef std::pair<const int, MyShmString > ValueType;
not
typedef std::pair<const int, StringAllocator> ValueType;
And similarly:
typedef MyShmString MappedType;
not
typedef StringAllocator MappedType;
Your types are different, is that intentional? MyShmString is not the same as MappedType - may be you ought to change the following line:
typedef StringAllocator MappedType;
to
typedef MyShmString MappedType;

Inserting a boost vector inside a boost map in shared memory

This is what i have so far. But this doesnt even compile. What should i do to make it work?
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);
how do i proceed now to insert this vector into the map?
This is one of the things that I tried
mymap->insert(std::pair<const int, vec>(i, myvec));
but doesnt seem to work. I kno that creating a pointer to a vector in shared memory is not the right way to go. I need to create an object for that if i am to insert it into the map. but how to do that or atleast how to incorporate these things in shared memory?
the error thrown by g++ is :
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> >]
line 54 is the return last line in main (its the return)
line 46 is the mymap-> insert line.
The problem is here:
vec *myvec = segment.construct<vec>("myvec")(std::less<int>(), vectorallocator);
there is no use for passing std::less<int> instance. Try this:
vec *myvec = segment.construct<vec>("myvec")(vectorallocator);