memory_algorithm_test.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #include <boost/interprocess/detail/config_begin.hpp>
  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. using namespace boost::interprocess;
  23. const int Memsize = 16384;
  24. const char *const shMemName = test::get_process_id_name();
  25. int test_simple_seq_fit()
  26. {
  27. //A shared memory with simple sequential fit algorithm
  28. typedef basic_managed_shared_memory
  29. <char
  30. ,simple_seq_fit<mutex_family>
  31. ,null_index
  32. > my_managed_shared_memory;
  33. //Create shared memory
  34. shared_memory_object::remove(shMemName);
  35. my_managed_shared_memory segment(create_only, shMemName, Memsize);
  36. //Now take the segment manager and launch memory test
  37. if(!test::test_all_allocation(*segment.get_segment_manager())){
  38. return 1;
  39. }
  40. return 0;
  41. }
  42. template<std::size_t Alignment>
  43. int test_rbtree_best_fit()
  44. {
  45. //A shared memory with red-black tree best fit algorithm
  46. typedef basic_managed_shared_memory
  47. <char
  48. ,rbtree_best_fit<mutex_family, offset_ptr<void>, Alignment>
  49. ,null_index
  50. > my_managed_shared_memory;
  51. //Create shared memory
  52. shared_memory_object::remove(shMemName);
  53. my_managed_shared_memory segment(create_only, shMemName, Memsize);
  54. //Now take the segment manager and launch memory test
  55. if(!test::test_all_allocation(*segment.get_segment_manager())){
  56. return 1;
  57. }
  58. return 0;
  59. }
  60. int main ()
  61. {
  62. const std::size_t void_ptr_align = ::boost::container::dtl::alignment_of<offset_ptr<void> >::value;
  63. if(test_simple_seq_fit()){
  64. return 1;
  65. }
  66. if(test_rbtree_best_fit<void_ptr_align>()){
  67. return 1;
  68. }
  69. if(test_rbtree_best_fit<2*void_ptr_align>()){
  70. return 1;
  71. }
  72. if(test_rbtree_best_fit<4*void_ptr_align>()){
  73. return 1;
  74. }
  75. shared_memory_object::remove(shMemName);
  76. return 0;
  77. }
  78. #include <boost/interprocess/detail/config_end.hpp>