Hi Boost-ers,
I am trying to create a boost::unordered_map in a boost::interprocess::managed_shared_memory segment. This works fine until I try to change from using boost::interprocess::allocator to boost::interprocess::cached_node_allocator.
It seems that the hash_bucket structure is deferring the key size calculation, but the cached_node_allocator needs the size at compilation time. Any ideas on how to make this work?
Below is a sample attempt which displays my problem along with the GCC output.
Thanks,
-Lenny
Sample code:
#include
#include
#include
#include
#include
using namespace boost::interprocess;
int main ()
{
//Create shared memory.
managed_shared_memory segment(create_only,
"SharedMem", //segment name
65536);
// Define cached node allocator type for char in a shared memory segment.
typedef boost::interprocess::
cached_node_allocator cached_node_allocator_t;
// Define an interprocess string type which uses the cached node allocator.
typedef boost::interprocess::
basic_string shared_string_t;
// Get an instance of the allocator.
cached_node_allocator_t allocator_instance(
segment.get_segment_manager());
// Create an unordered map with Key and Value as interprocess strings, using the default hash and predicate
// and use the cached node allocator.
boost::unordered_map,
std::equal_to,
cached_node_allocator_t> my_map_t(allocator_instance);
return 0;
}
GCC output:
$ g++ -I/opt/local/include cnasum.cc
/opt/local/include/boost/interprocess/allocators/detail/allocator_common.hpp: In instantiation of ‘const size_t boost::interprocess::sizeof_value, boost::interprocess::iset_index>, 64ul> >, boost::container::basic_string, boost::interprocess::iset_index>, 64ul> > >, boost::interprocess::segment_manager, boost::interprocess::iset_index>, 64ul> > >::value’:
/opt/local/include/boost/interprocess/allocators/cached_node_allocator.hpp:104: instantiated from ‘boost::interprocess::cached_node_allocator, boost::interprocess::iset_index>, 64ul> >, boost::container::basic_string, boost::interprocess::iset_index>, 64ul> > >, boost::interprocess::segment_manager, boost::interprocess::iset_index>, 64ul> >, boost::interprocess::segment_manager, boost::interprocess::iset_index>, 64ul>’
/opt/local/include/boost/unordered/detail/fwd.hpp:134: instantiated from ‘boost::unordered_detail::hash_bucket, boost::interprocess::iset_index>, 64ul> >, boost::container::basic_string, boost::interprocess::iset_index>, 64ul> > >, boost::interprocess::segment_manager, boost::interprocess::iset_index>, 64ul> >’
/opt/local/include/boost/unordered/detail/fwd.hpp:278: instantiated from ‘boost::unordered_detail::hash_iterator_base, boost::interprocess::iset_index>, 64ul> >, boost::container::basic_string, boost::interprocess::iset_index>, 64ul> > >, boost::interprocess::segment_manager, boost::interprocess::iset_index>, 64ul>, boost::unordered_detail::ungrouped>’
/opt/local/include/boost/unordered/detail/fwd.hpp:347: instantiated from ‘boost::unordered_detail::hash_buckets, boost::interprocess::iset_index>, 64ul> >, boost::container::basic_string, boost::interprocess::iset_index>, 64ul> > >, boost::interprocess::segment_manager, boost::interprocess::iset_index>, 64ul>, boost::unordered_detail::ungrouped>’
/opt/local/include/boost/unordered/detail/fwd.hpp:921: instantiated from ‘boost::unordered_detail::types, boost::interprocess::iset_index>, 64ul> >, std::pair, boost::interprocess::iset_index>, 64ul> >, boost::container::basic_string, boost::interprocess::iset_index>, 64ul> > >, boost::hash, boost::interprocess::iset_index>, 64ul> > >, std::equal_to, boost::interprocess::iset_index>, 64ul> > >, boost::interprocess::cached_node_allocator, boost::interprocess::iset_index>, 64ul> >, boost::container::basic_string, boost::interprocess::iset_index>, 64ul> > >, boost::interprocess::segment_manager, boost::interprocess::iset_index>, 64ul>, boost::unordered_detail::map_extractor, boost::interprocess::iset_index>, 64ul> >, std::pair, boost::interprocess::iset_index>, 64ul> >, boost::container::basic_string, boost::interprocess::iset_index>, 64ul> > > >, boost::unordered_detail::ungrouped>’
/opt/local/include/boost/unordered/detail/unique.hpp:125: instantiated from ‘boost::unordered_detail::map, boost::interprocess::iset_index>, 64ul> >, boost::hash, boost::interprocess::iset_index>, 64ul> > >, std::equal_to, boost::interprocess::iset_index>, 64ul> > >, boost::interprocess::cached_node_allocator, boost::interprocess::iset_index>, 64ul> >, boost::container::basic_string, boost::interprocess::iset_index>, 64ul> > >, boost::interprocess::segment_manager, boost::interprocess::iset_index>, 64ul> >’
/opt/local/include/boost/unordered/unordered_map.hpp:63: instantiated from ‘boost::unordered_map, boost::interprocess::iset_index>, 64ul> >, boost::container::basic_string, boost::interprocess::iset_index>, 64ul> >, boost::hash, boost::interprocess::iset_index>, 64ul> > >, std::equal_to, boost::interprocess::iset_index>, 64ul> > >, boost::interprocess::cached_node_allocator, boost::interprocess::iset_index>, 64ul> >’
cnasum.cc:35: instantiated from here
/opt/local/include/boost/interprocess/allocators/detail/allocator_common.hpp:43: error: invalid application of ‘sizeof’ to incomplete type ‘boost::unordered_detail::hash_bucket, boost::interprocess::iset_index>, 64ul> >, boost::container::basic_string, boost::interprocess::iset_index>, 64ul> > >, boost::interprocess::segment_manager, boost::interprocess::iset_index>, 64ul> >’
$