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 #include <boost/interprocess/detail/config_begin.hpp>
12 #include <boost/interprocess/managed_shared_memory.hpp>
13 #include <boost/interprocess/mem_algo/simple_seq_fit.hpp>
14 #include <boost/interprocess/mem_algo/rbtree_best_fit.hpp>
15 #include <boost/interprocess/indexes/null_index.hpp>
16 #include <boost/interprocess/sync/mutex_family.hpp>
17 #include <boost/interprocess/detail/type_traits.hpp>
18 #include <boost/move/detail/type_traits.hpp> //make_unsigned, alignment_of
19 #include "memory_algorithm_test_template.hpp"
22 #include "get_process_id_name.hpp"
24 using namespace boost::interprocess
;
26 const int Memsize
= 16384;
27 const char *const shMemName
= test::get_process_id_name();
29 int test_simple_seq_fit()
31 //A shared memory with simple sequential fit algorithm
32 typedef basic_managed_shared_memory
34 ,simple_seq_fit
<mutex_family
>
36 > my_managed_shared_memory
;
38 //Create shared memory
39 shared_memory_object::remove(shMemName
);
40 my_managed_shared_memory
segment(create_only
, shMemName
, Memsize
);
42 //Now take the segment manager and launch memory test
43 if(!test::test_all_allocation(*segment
.get_segment_manager())){
49 template<std::size_t Alignment
>
50 int test_rbtree_best_fit()
52 //A shared memory with red-black tree best fit algorithm
53 typedef basic_managed_shared_memory
55 ,rbtree_best_fit
<mutex_family
, offset_ptr
<void>, Alignment
>
57 > my_managed_shared_memory
;
59 //Create shared memory
60 shared_memory_object::remove(shMemName
);
61 my_managed_shared_memory
segment(create_only
, shMemName
, Memsize
);
63 //Now take the segment manager and launch memory test
64 if(!test::test_all_allocation(*segment
.get_segment_manager())){
72 const std::size_t void_ptr_align
= ::boost::container::dtl::alignment_of
<offset_ptr
<void> >::value
;
74 if(test_simple_seq_fit()){
77 if(test_rbtree_best_fit
<void_ptr_align
>()){
80 if(test_rbtree_best_fit
<2*void_ptr_align
>()){
83 if(test_rbtree_best_fit
<4*void_ptr_align
>()){
87 shared_memory_object::remove(shMemName
);
91 #include <boost/interprocess/detail/config_end.hpp>