Ticket #6969: test.cpp

File test.cpp, 1008 bytes (added by Trystan Larey-Williams <trystan@…>, 10 years ago)
Line 
1
2#include <boost/interprocess/managed_shared_memory.hpp>
3#include <boost/interprocess/containers/map.hpp>
4#include <boost/interprocess/containers/pair.hpp>
5#include <boost/interprocess/allocators/allocator.hpp>
6
7using namespace boost::interprocess;
8
9class Foo {
10public:
11 Foo() {
12 m_shm = new managed_shared_memory( open_or_create, "/testSM", 4096000 );
13
14 const ShmAlloc allocator( m_shm->get_segment_manager() );
15 m_connections = m_shm->find_or_construct<ShmMap>(unique_instance)(std::less<unsigned int>(), allocator);
16
17 delete m_shm;
18 }
19
20private:
21
22 typedef boost::interprocess::pair<unsigned int, unsigned int> MyPair;
23
24 typedef boost::interprocess::allocator<MyPair,
25 boost::interprocess::managed_shared_memory::segment_manager> ShmAlloc;
26
27 typedef boost::interprocess::map<unsigned int, unsigned int, std::less<unsigned int>, ShmAlloc> ShmMap;
28
29 boost::interprocess::offset_ptr<ShmMap> m_connections;
30 boost::interprocess::managed_shared_memory* m_shm;
31};
32
33int main( void ) {
34 Foo();
35 return(0);
36}
37