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>
13 #include <boost/interprocess/managed_shared_memory.hpp>
14 #include <boost/interprocess/allocators/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,test::get_process_id_name(), 65536);
46 managed_shared_memory segment(create_only,
47 "MySharedMemory", //segment name
53 //Create an allocator that allocates ints from the managed segment
54 allocator<int, managed_shared_memory::segment_manager>
55 allocator_instance(segment.get_segment_manager());
57 //Copy constructed allocator is equal
58 allocator<int, managed_shared_memory::segment_manager>
59 allocator_instance2(allocator_instance);
60 assert(allocator_instance2 == allocator_instance);
62 //Allocate and deallocate memory for 100 ints
63 allocator_instance2.deallocate(allocator_instance.allocate(100), 100);
68 #include <boost/interprocess/detail/config_end.hpp>