]>
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/allocators/allocator.hpp>
12 #include <boost/interprocess/managed_shared_memory.hpp>
13 #include <boost/interprocess/containers/vector.hpp>
14 #include <boost/interprocess/containers/list.hpp>
17 #include "print_container.hpp"
18 #include "get_process_id_name.hpp"
20 using namespace boost::interprocess
;
24 const int memsize
= 65536;
25 std::string process_name
;
26 test::get_process_id_name(process_name
);
27 const char *const shMemName
= process_name
.c_str();
30 shared_memory_object::remove(shMemName
);
32 //Create shared memory
33 managed_shared_memory
segment(create_only
, shMemName
, memsize
);
35 //STL compatible allocator object, uses allocate(), deallocate() functions
36 typedef allocator
<int, managed_shared_memory::segment_manager
>
37 shmem_allocator_int_t
;
39 const shmem_allocator_int_t
myallocator (segment
.get_segment_manager());
44 const char *allocName
= "testAllocation";
46 typedef boost::interprocess::vector
<int, shmem_allocator_int_t
> MyVect
;
48 //---- ALLOC, NAMED_ALLOC, NAMED_NEW TEST ----//
51 //Let's allocate some memory
52 for(i
= 0; i
< max
; ++i
){
53 array
[std::ptrdiff_t(i
)] = segment
.allocate(i
+1u);
56 //Deallocate allocated memory
57 for(i
= 0; i
< max
; ++i
){
58 segment
.deallocate(array
[std::ptrdiff_t(i
)]);
66 shmem_vect
= segment
.construct
<MyVect
> (allocName
) (myallocator
);
67 res
= (shmem_vect
== segment
.find
<MyVect
>(allocName
).first
);
70 //Destroy and check it is not present
71 segment
.destroy
<MyVect
> (allocName
);
72 res
= (0 == segment
.find
<MyVect
>(allocName
).first
);
76 //Construct, dump to a file
77 shmem_vect
= segment
.construct
<MyVect
> (allocName
) (myallocator
);
79 if(shmem_vect
!= segment
.find
<MyVect
>(allocName
).first
)
81 //Destroy and check it is not present
82 segment
.destroy
<MyVect
> (allocName
);
83 res
= (0 == segment
.find
<MyVect
>(allocName
).first
);
89 shared_memory_object::remove(shMemName
);
92 shared_memory_object::remove(shMemName
);