• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //////////////////////////////////////////////////////////////////////////////
2 //
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)
6 //
7 // See http://www.boost.org/libs/interprocess for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10 
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"
19 #include <iostream>
20 #include <string>
21 #include "get_process_id_name.hpp"
22 
23 using namespace boost::interprocess;
24 
25 const int Memsize = 16384;
26 const char *const shMemName = test::get_process_id_name();
27 
test_simple_seq_fit()28 int test_simple_seq_fit()
29 {
30    //A shared memory with simple sequential fit algorithm
31    typedef basic_managed_shared_memory
32       <char
33       ,simple_seq_fit<mutex_family>
34       ,null_index
35       > my_managed_shared_memory;
36 
37    //Create shared memory
38    shared_memory_object::remove(shMemName);
39    my_managed_shared_memory segment(create_only, shMemName, Memsize);
40 
41    //Now take the segment manager and launch memory test
42    if(!test::test_all_allocation(*segment.get_segment_manager())){
43       return 1;
44    }
45    return 0;
46 }
47 
48 template<std::size_t Alignment>
test_rbtree_best_fit()49 int test_rbtree_best_fit()
50 {
51    //A shared memory with red-black tree best fit algorithm
52    typedef basic_managed_shared_memory
53       <char
54       ,rbtree_best_fit<mutex_family, offset_ptr<void>, Alignment>
55       ,null_index
56       > my_managed_shared_memory;
57 
58    //Create shared memory
59    shared_memory_object::remove(shMemName);
60    my_managed_shared_memory segment(create_only, shMemName, Memsize);
61 
62    //Now take the segment manager and launch memory test
63    if(!test::test_all_allocation(*segment.get_segment_manager())){
64       return 1;
65    }
66    return 0;
67 }
68 
main()69 int main ()
70 {
71    const std::size_t void_ptr_align = ::boost::container::dtl::alignment_of<offset_ptr<void> >::value;
72 
73    if(test_simple_seq_fit()){
74       return 1;
75    }
76    if(test_rbtree_best_fit<void_ptr_align>()){
77       return 1;
78    }
79    if(test_rbtree_best_fit<2*void_ptr_align>()){
80       return 1;
81    }
82    if(test_rbtree_best_fit<4*void_ptr_align>()){
83       return 1;
84    }
85 
86    shared_memory_object::remove(shMemName);
87    return 0;
88 }
89