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/managed_shared_memory.hpp>
12 #include <boost/interprocess/mem_algo/simple_seq_fit.hpp>
13 #include <boost/interprocess/mem_algo/rbtree_best_fit.hpp>
14 #include <boost/interprocess/indexes/null_index.hpp>
15 #include <boost/interprocess/sync/mutex_family.hpp>
16 #include <boost/interprocess/detail/type_traits.hpp>
17 #include <boost/move/detail/type_traits.hpp> //make_unsigned, alignment_of
18 #include "memory_algorithm_test_template.hpp"
21 #include "get_process_id_name.hpp"
23 using namespace boost::interprocess
;
25 const int Memsize
= 16384;
26 const char *const shMemName
= test::get_process_id_name();
28 int test_simple_seq_fit()
30 //A shared memory with simple sequential fit algorithm
31 typedef basic_managed_shared_memory
33 ,simple_seq_fit
<mutex_family
>
35 > my_managed_shared_memory
;
37 //Create shared memory
38 shared_memory_object::remove(shMemName
);
39 my_managed_shared_memory
segment(create_only
, shMemName
, Memsize
);
41 //Now take the segment manager and launch memory test
42 if(!test::test_all_allocation(*segment
.get_segment_manager())){
48 template<std::size_t Alignment
>
49 int test_rbtree_best_fit()
51 //A shared memory with red-black tree best fit algorithm
52 typedef basic_managed_shared_memory
54 ,rbtree_best_fit
<mutex_family
, offset_ptr
<void>, Alignment
>
56 > my_managed_shared_memory
;
58 //Create shared memory
59 shared_memory_object::remove(shMemName
);
60 my_managed_shared_memory
segment(create_only
, shMemName
, Memsize
);
62 //Now take the segment manager and launch memory test
63 if(!test::test_all_allocation(*segment
.get_segment_manager())){
71 const std::size_t void_ptr_align
= ::boost::container::dtl::alignment_of
<offset_ptr
<void> >::value
;
73 if(test_simple_seq_fit()){
76 if(test_rbtree_best_fit
<void_ptr_align
>()){
79 if(test_rbtree_best_fit
<2*void_ptr_align
>()){
82 if(test_rbtree_best_fit
<4*void_ptr_align
>()){
86 shared_memory_object::remove(shMemName
);