]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/interprocess/test/data_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"
19 #include "get_process_id_name.hpp"
21 using namespace boost::interprocess
;
25 const int memsize
= 65536;
26 std::string process_name
;
27 test::get_process_id_name(process_name
);
28 const char *const shMemName
= process_name
.c_str();
31 shared_memory_object::remove(shMemName
);
33 //Create shared memory
34 managed_shared_memory
segment(create_only
, shMemName
, memsize
);
36 //STL compatible allocator object, uses allocate(), deallocate() functions
37 typedef allocator
<int, managed_shared_memory::segment_manager
>
38 shmem_allocator_int_t
;
40 const shmem_allocator_int_t
myallocator (segment
.get_segment_manager());
45 const char *allocName
= "testAllocation";
47 typedef boost::interprocess::vector
<int, shmem_allocator_int_t
> MyVect
;
49 //---- ALLOC, NAMED_ALLOC, NAMED_NEW TEST ----//
52 //Let's allocate some memory
53 for(i
= 0; i
< max
; ++i
){
54 array
[i
] = segment
.allocate(i
+1);
57 //Deallocate allocated memory
58 for(i
= 0; i
< max
; ++i
){
59 segment
.deallocate(array
[i
]);
67 shmem_vect
= segment
.construct
<MyVect
> (allocName
) (myallocator
);
68 res
= (shmem_vect
== segment
.find
<MyVect
>(allocName
).first
);
71 //Destroy and check it is not present
72 segment
.destroy
<MyVect
> (allocName
);
73 res
= (0 == segment
.find
<MyVect
>(allocName
).first
);
77 //Construct, dump to a file
78 shmem_vect
= segment
.construct
<MyVect
> (allocName
) (myallocator
);
80 if(shmem_vect
!= segment
.find
<MyVect
>(allocName
).first
)
82 //Destroy and check it is not present
83 segment
.destroy
<MyVect
> (allocName
);
84 res
= (0 == segment
.find
<MyVect
>(allocName
).first
);
90 shared_memory_object::remove(shMemName
);
93 shared_memory_object::remove(shMemName
);
97 #include <boost/interprocess/detail/config_end.hpp>