|
Boost Users : |
Subject: [Boost-users] Shared memory: private node allocator for a boost::unordered_map
From: trafdev (trafdev_at_[hidden])
Date: 2016-05-09 14:04:51
Hello.
I'm trying to use a private node allocator for an unordered_map placed
in the shared memory:
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/containers/map.hpp>
#include <boost/unordered_map.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/allocators/private_node_allocator.hpp>
#include <functional>
#include <utility>
int main ()
{
using namespace boost::interprocess;
struct shm_remove
{
shm_remove() { shared_memory_object::remove("MySharedMemory"); }
~shm_remove(){ shared_memory_object::remove("MySharedMemory"); }
} remover;
managed_shared_memory segment
(create_only
,"MySharedMemory" //segment name
,65536); //segment size in bytes
typedef int KeyType;
typedef float MappedType;
typedef std::pair<const int, float> ValueType;
typedef private_node_allocator<ValueType,
managed_shared_memory::segment_manager>
ShmemAllocator;
typedef boost::unordered_map<KeyType, MappedType,
boost::hash<KeyType>, std::equal_to<KeyType>, ShmemAllocator> MyMap;
ShmemAllocator alloc_inst (segment.get_segment_manager());
MyMap *mymap =
segment.construct<MyMap>("MyMap") //object name
(3,
boost::hash<KeyType>(),
std::equal_to<KeyType>(),
alloc_inst);
for(int i = 0; i < 100; ++i){
mymap->insert(std::pair<const int, float>(i, (float)i));
}
return 0;
}
It gives a compilation error:
/usr/local/include/boost/unordered/detail/unique.hpp:30:43: error: no
type named 'pointer' in
'boost::interprocess::private_node_allocator<boost::unordered::detail::unique_node<boost::interprocess::private_node_allocator<std::__1::pair<const
int, float>, 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>, 64>, std::__1::pair<const int, float> >,
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>, 64>'
A, unique_node<A, T> >::type::pointer node_pointer;
What am I doing wrong?
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net