1//////////////////////////////////////////////////////////////////////////////
2//
3// (C) Copyright Ion Gaztanaga 2006-2012. 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)
6//
7// See http://www.boost.org/libs/interprocess for documentation.
8//
9//////////////////////////////////////////////////////////////////////////////
10
11#include <boost/interprocess/detail/workaround.hpp>
12//[doc_private_adaptive_pool
13#include <boost/interprocess/managed_shared_memory.hpp>
14#include <boost/interprocess/allocators/private_adaptive_pool.hpp>
15#include <cassert>
16//<-
17#include "../test/get_process_id_name.hpp"
18//->
19
20using namespace boost::interprocess;
21
22int main ()
23{
24 //Remove shared memory on construction and destruction
25 struct shm_remove
26 {
27 //<-
28 #if 1
29 shm_remove() { shared_memory_object::remove(filename: test::get_process_id_name()); }
30 ~shm_remove(){ shared_memory_object::remove(filename: test::get_process_id_name()); }
31 #else
32 //->
33 shm_remove() { shared_memory_object::remove("MySharedMemory"); }
34 ~shm_remove(){ shared_memory_object::remove("MySharedMemory"); }
35 //<-
36 #endif
37 //->
38 } remover;
39 //<-
40 (void)remover;
41 //->
42
43 //Create shared memory
44 //<-
45 #if 1
46 managed_shared_memory segment(create_only,
47 test::get_process_id_name(), //segment name
48 65536);
49 #else
50 //->
51 managed_shared_memory segment(create_only,
52 "MySharedMemory", //segment name
53 65536);
54 //<-
55 #endif
56 //->
57
58 //Create a private_adaptive_pool that allocates ints from the managed segment
59 //The number of chunks per segment is the default value
60 typedef private_adaptive_pool<int, managed_shared_memory::segment_manager>
61 private_adaptive_pool_t;
62 private_adaptive_pool_t allocator_instance(segment.get_segment_manager());
63
64 //Create another private_adaptive_pool.
65 private_adaptive_pool_t allocator_instance2(segment.get_segment_manager());
66
67 //Although the segment manager address
68 //is the same, this private_adaptive_pool will have its own pool so
69 //"allocator_instance2" CAN'T deallocate nodes allocated by "allocator_instance".
70 //"allocator_instance2" is NOT equal to "allocator_instance"
71 assert(allocator_instance != allocator_instance2);
72
73 //Create another adaptive_pool using copy-constructor.
74 private_adaptive_pool_t allocator_instance3(allocator_instance2);
75
76 //This allocator is also unequal to allocator_instance2
77 assert(allocator_instance2 != allocator_instance3);
78
79 //Pools are destroyed with the allocators
80 return 0;
81}
82//]
83
84

source code of boost/libs/interprocess/example/doc_private_adaptive_pool.cpp