]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/interprocess/example/doc_managed_raw_allocation.cpp
1 //////////////////////////////////////////////////////////////////////////////
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)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 //[doc_managed_raw_allocation
12 #include <boost/interprocess/managed_shared_memory.hpp>
14 #include "../test/get_process_id_name.hpp"
19 using namespace boost::interprocess
;
21 //Remove shared memory on construction and destruction
26 shm_remove() { shared_memory_object::remove(test::get_process_id_name()); }
27 ~shm_remove(){ shared_memory_object::remove(test::get_process_id_name()); }
30 shm_remove() { shared_memory_object::remove("MySharedMemory"); }
31 ~shm_remove(){ shared_memory_object::remove("MySharedMemory"); }
40 //Managed memory segment that allocates portions of a shared memory
41 //segment with the default management algorithm
44 managed_shared_memory
managed_shm(create_only
,test::get_process_id_name(), 65536);
47 managed_shared_memory
managed_shm(create_only
,"MySharedMemory", 65536);
52 //Allocate 100 bytes of memory from segment, throwing version
53 void *ptr
= managed_shm
.allocate(100);
56 managed_shm
.deallocate(ptr
);
58 //Non throwing version
59 ptr
= managed_shm
.allocate(100, std::nothrow
);
62 managed_shm
.deallocate(ptr
);