[interprocess] Shared memory compile problem

I am a new user and try to write some codes with shared memory using boost.interprocess. Basically, I followed the examples and the allocation seems fine. But the use of shared-memory container gave me a bunch of error messages related to "instantiated from here." during compile. The error seems related to the template. But I have no idea how to fix it yet. Any suggestion would be helpful. Thanks. Po-Chun My code: struct LongIntLess { bool operator()(const uint64_t a, const uint64_t b) { return a < b; } }; main () { using namespace boost::interprocess; try{ shared_memory_object::remove("SharedMemory"); managed_shared_memory segment (create_only, "SharedMemory", sizeof (uint64_t)*200); typedef allocator< uint64_t, managed_shared_memory::segment_manager> shmAllocator_t; typedef set<uint64_t, shmAllocator_t> shrSet_t; const shmAllocator_t alloc_inst (segment.get_segment_manager()); shrSet_t *WrSet_1; WrSet_1 = segment.construct<shrSet_t> ("shrSet_t") ("LongIntLess", alloc_inst); // <= not sure about this // Is it right way to construct a set ? WrSet_1->insert(2); // <====== This line causes the error } catch (...){ shared_memory_object::remove("SharedMemory"); throw(); } shared_memory_object::remove("SharedMemory"); } The error messages are from these files: boost/interprocess/containers/ detail/tree.hpp: boost/intrusive/detail/tree_algorithms.hpp boost/intrusive/rbtree.hpp boost/interprocess/containers/detail/tree.hpp boost/interprocess/containers/set.hpp One of the error messges is like: tree.hpp:331: instantiated from 'bool boost::interprocess::detail::rbtree<Key, Value, KeyOfValue, KeyCompare, A>::key_node_compare<KeyValueCompare>::operator()(const KeyType&, const typename boost::interprocess::detail::node_alloc_holder<A, typename boost::interprocess::detail::intrusive_rbtree_type<A, boost::interprocess::detail::value_compare_impl<Key, Value, KeyCompare, KeyOfValue> >::type>::Node&) const [with KeyType = long unsigned int, KeyValueCompare = boost::interprocess::detail::value_compare_impl<long unsigned int, long unsigned int, boost::interprocess::allocator<long unsigned 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> >, boost::interprocess::detail::identity<long unsigned int> >, Key = long unsigned int, Value = long unsigned int, KeyOfValue = boost::interprocess::detail::identity<long unsigned int>, KeyCompare = boost::interprocess::allocator<long unsigned 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> >, A = std::allocator<long unsigned int>]'

Po-Chun wrote:
I am a new user and try to write some codes with shared memory using boost.interprocess. Basically, I followed the examples and the allocation seems fine. But the use of shared-memory container gave me a bunch of error messages related to "instantiated from here." during compile. The error seems related to the template. But I have no idea how to fix it yet. Any suggestion would be helpful. Thanks.
set's constructor is equal to std::constructor, but you must pay more attention because it needs an allocator and set's constructor taking the allocator takes also the comparison option. You have several C++ errors in your code (set's template arguments are not correct, for example). This should compile fine: #include <boost/interprocess/managed_shared_memory.hpp> #include <boost/interprocess/containers/set.hpp> #include <boost/cstdint.hpp> #include <boost/interprocess/allocators/allocator.hpp> #include <functional> #include <utility> struct LongIntLess { bool operator()(const boost::uint64_t a, const boost::uint64_t b) const { return a < b; } }; int main () { using namespace boost::interprocess; try{ shared_memory_object::remove("SharedMemory"); managed_shared_memory segment (create_only, "SharedMemory", sizeof(boost::uint64_t)*200); typedef allocator< boost::uint64_t, managed_shared_memory::segment_manager> shmAllocator_t; typedef set<boost::uint64_t, LongIntLess, shmAllocator_t> shrSet_t; const shmAllocator_t alloc_inst (segment.get_segment_manager()); shrSet_t *WrSet_1; WrSet_1 = segment.construct<shrSet_t> ("shrSet_t") (LongIntLess(), alloc_inst); WrSet_1->insert(2); } catch (...){ shared_memory_object::remove("SharedMemory"); throw; } shared_memory_object::remove("SharedMemory"); } Ion

Thanks for the response, Ion. Is there any hash set container for the shared memory? Po-Chun On Apr 21, 12:54 pm, Ion Gaztañaga <igaztan...@gmail.com> wrote:
Po-Chunwrote:
I am a new user and try to write some codes with shared memory using boost.interprocess. Basically, I followed the examples and the allocation seems fine. But the use of shared-memory container gave me a bunch of error messages related to "instantiated from here." during compile. The error seems related to the template. But I have no idea how to fix it yet. Any suggestion would be helpful. Thanks.
set's constructor is equal to std::constructor, but you must pay more attention because it needs an allocator and set's constructor taking the allocator takes also the comparison option. You have several C++ errors in your code (set's template arguments are not correct, for example).
This should compile fine:
#include <boost/interprocess/managed_shared_memory.hpp> #include <boost/interprocess/containers/set.hpp> #include <boost/cstdint.hpp> #include <boost/interprocess/allocators/allocator.hpp> #include <functional> #include <utility>
struct LongIntLess { bool operator()(const boost::uint64_t a, const boost::uint64_t b) const { return a < b; }
};
int main () { using namespace boost::interprocess; try{ shared_memory_object::remove("SharedMemory"); managed_shared_memory segment (create_only, "SharedMemory", sizeof(boost::uint64_t)*200);
typedef allocator< boost::uint64_t, managed_shared_memory::segment_manager> shmAllocator_t;
typedef set<boost::uint64_t, LongIntLess, shmAllocator_t> shrSet_t;
const shmAllocator_t alloc_inst (segment.get_segment_manager()); shrSet_t *WrSet_1; WrSet_1 = segment.construct<shrSet_t> ("shrSet_t") (LongIntLess(), alloc_inst);
WrSet_1->insert(2); } catch (...){ shared_memory_object::remove("SharedMemory"); throw; } shared_memory_object::remove("SharedMemory");
}
Ion _______________________________________________ Boost-users mailing list Boost-us...@lists.boost.orghttp://lists.boost.org/mailman/listinfo.cgi/boost-users

Po-Chun wrote:
Thanks for the response, Ion.
Is there any hash set container for the shared memory?
Boost.Unordered is compatible with shared memory. It's mentioned in the documentation: http://www.boost.org/doc/libs/1_38_0/doc/html/interprocess/allocators_contai... Best, Ion
participants (2)
-
Ion Gaztañaga
-
Po-Chun