]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/interprocess/test/allocexcept_test.cpp
1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2004-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 #include <boost/interprocess/detail/config_begin.hpp>
12 #include <boost/interprocess/allocators/allocator.hpp>
13 #include <boost/interprocess/managed_shared_memory.hpp>
14 #include <boost/interprocess/containers/vector.hpp>
15 #include <boost/interprocess/containers/list.hpp>
18 #include "print_container.hpp"
20 #include "get_process_id_name.hpp"
22 struct InstanceCounter
24 InstanceCounter(){++counter
;}
25 InstanceCounter(const InstanceCounter
&){++counter
;}
26 ~InstanceCounter(){--counter
;}
27 static std::size_t counter
;
30 std::size_t InstanceCounter::counter
= 0;
32 using namespace boost::interprocess
;
37 const int memsize
= 16384;
38 const char *const shMemName
= test::get_process_id_name();
41 shared_memory_object::remove(shMemName
);
43 //Named allocate capable shared mem allocator
44 managed_shared_memory
segment(create_only
, shMemName
, memsize
);
46 //STL compatible allocator object, uses allocate(), deallocate() functions
47 typedef allocator
<InstanceCounter
,
48 managed_shared_memory::segment_manager
>
50 const inst_allocator_t
myallocator (segment
.get_segment_manager());
52 typedef vector
<InstanceCounter
, inst_allocator_t
> MyVect
;
54 //We'll provoke an exception, let's see if exception handling works
56 //Fill vector until there is no more memory
57 MyVect
myvec(myallocator
);
59 for(i
= 0; true; ++i
){
60 myvec
.push_back(InstanceCounter());
63 catch(boost::interprocess::bad_alloc
&){
64 if(InstanceCounter::counter
!= 0)
68 //We'll provoke an exception, let's see if exception handling works
70 //Fill vector at the beginning until there is no more memory
71 MyVect
myvec(myallocator
);
74 for(i
= 0; true; ++i
){
75 myvec
.insert(myvec
.begin(), i
, ic
);
78 catch(boost::interprocess::bad_alloc
&){
79 if(InstanceCounter::counter
!= 0)
82 catch(std::length_error
&){
83 if(InstanceCounter::counter
!= 0)
88 shared_memory_object::remove(shMemName
);
91 shared_memory_object::remove(shMemName
);
95 #include <boost/interprocess/detail/config_end.hpp>