1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2006-2009. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 //////////////////////////////////////////////////////////////////////////////
10 #include <boost/interprocess/detail/config_begin.hpp>
11 #include <boost/interprocess/detail/workaround.hpp>
12 //[doc_private_node_allocator
13 #include <boost/interprocess/managed_shared_memory.hpp>
14 #include <boost/interprocess/allocators/private_node_allocator.hpp>
17 #include "../test/get_process_id_name.hpp"
20 using namespace boost::interprocess;
24 //Remove shared memory on construction and destruction
29 shm_remove() { shared_memory_object::remove(test::get_process_id_name()); }
30 ~shm_remove(){ shared_memory_object::remove(test::get_process_id_name()); }
33 shm_remove() { shared_memory_object::remove("MySharedMemory"); }
34 ~shm_remove(){ shared_memory_object::remove("MySharedMemory"); }
40 //Create shared memory
43 managed_shared_memory segment(create_only,
44 test::get_process_id_name(), //segment name
48 managed_shared_memory segment(create_only,
49 "MySharedMemory", //segment name
55 //Create a private_node_allocator that allocates ints from the managed segment
56 //The number of chunks per segment is the default value
57 typedef private_node_allocator<int, managed_shared_memory::segment_manager>
58 private_node_allocator_t;
59 private_node_allocator_t allocator_instance(segment.get_segment_manager());
61 //Create another private_node_allocator.
62 private_node_allocator_t allocator_instance2(segment.get_segment_manager());
64 //Although the segment manager address
65 //is the same, this private_node_allocator will have its own pool so
66 //"allocator_instance2" CAN'T deallocate nodes allocated by "allocator_instance".
67 //"allocator_instance2" is NOT equal to "allocator_instance"
68 assert(allocator_instance != allocator_instance2);
70 //Create another node_allocator using copy-constructor.
71 private_node_allocator_t allocator_instance3(allocator_instance2);
73 //This allocator is also unequal to allocator_instance2
74 assert(allocator_instance2 != allocator_instance3);
76 //Pools are destroyed with the allocators
80 #include <boost/interprocess/detail/config_end.hpp>