mardi 23 février 2021

BOOST 1.73.0 Interprocess string allocator error

I'm trying to allocate a string inside a custom object SharedValue in shared memory using Boost 1.73.0

My object:

typedef boost::interprocess::allocator<char, boost::interprocess::managed_shared_memory::segment_manager> char_allocator;

class SharedValue {
public:
  SharedValue(const char_allocator& ca);
  boost::interprocess::basic_string<char, std::char_traits<char>, char_allocator> val;
};

SharedValue::SharedValue(const char_allocator& ca) : val(ca) {}

Then in the shared memory builder:

boost::interprocess::managed_shared_memory shm(boost::interprocess::open_or_create, "SharedMemory", 65536);
boost::interprocess::managed_shared_memory::allocator<char>::type ca(shm.get_allocator<char>());
auto *value = shm.find_or_construct<SharedValue>(string(ID + "_" + name + "_SharedValueSHM").c_str())(ca);

And it gives me this error:

In file included from boost/include/boost/interprocess/containers/string.hpp:23,
                 from SharedValue.h:24,
                 from SharedValue.cpp:13:
boost/include/boost/container/string.hpp: In instantiation of ‘boost::container::dtl::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:100:18:   required from ‘boost::container::dtl::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:643: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> >]’
SharedValue.cpp:19:50:   required from here
boost/include/boost/container/string.hpp:220:27: 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()’
  220 |          : allocator_type()
      |                           ^
In file included from boost/include/boost/interprocess/segment_manager.hpp:38,
                 from boost/include/boost/interprocess/detail/managed_memory_impl.hpp:30,
                 from boost/include/boost/interprocess/managed_shared_memory.hpp:25,
                 from SharedValue.h:21,
                 from SharedValue.cpp:13:
boost/include/boost/interprocess/allocators/allocator.hpp:142:4: note: candidate: ‘template<class T2> boost::interprocess::allocator<T, SegmentManager>::allocator(const boost::interprocess::allocator<T2, SegmentManager>&)’
  142 |    allocator(const allocator<T2, SegmentManager> &other)
      |    ^~~~~~~~~
boost/include/boost/interprocess/allocators/allocator.hpp:142:4: note:   template argument deduction/substitution failed:
In file included from boost/include/boost/interprocess/containers/string.hpp:23,
                 from SharedValue.h:24,
                 from SharedValue.cpp:13:
boost/include/boost/container/string.hpp:220:27: note:   candidate expects 1 argument, 0 provided
  220 |          : allocator_type()
      |                           ^
In file included from boost/include/boost/interprocess/segment_manager.hpp:38,
                 from boost/include/boost/interprocess/detail/managed_memory_impl.hpp:30,
                 from boost/include/boost/interprocess/managed_shared_memory.hpp:25,
                 from SharedValue.h:21,
                 from SharedValue.cpp:13:
boost/include/boost/interprocess/allocators/allocator.hpp:136:4: note: candidate: ‘boost::interprocess::allocator<T, SegmentManager>::allocator(const boost::interprocess::allocator<T, SegmentManager>&) [with T = char; SegmentManager = boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index>]’
  136 |    allocator(const allocator &other)
      |    ^~~~~~~~~
boost/include/boost/interprocess/allocators/allocator.hpp:136:4: note:   candidate expects 1 argument, 0 provided
boost/include/boost/interprocess/allocators/allocator.hpp:131:4: note: candidate: ‘boost::interprocess::allocator<T, SegmentManager>::allocator(boost::interprocess::allocator<T, SegmentManager>::segment_manager*) [with T = char; SegmentManager = boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index>; boost::interprocess::allocator<T, SegmentManager>::segment_manager = boost::interprocess::segment_manager<char, boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>, boost::interprocess::iset_index>]’
  131 |    allocator(segment_manager *segment_mngr)
      |    ^~~~~~~~~
boost/include/boost/interprocess/allocators/allocator.hpp:131:4: note:   candidate expects 1 argument, 0 provided

Anyone have some ideas to solve this error?

Thanks

Aucun commentaire:

Enregistrer un commentaire