null_index_test.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-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/indexes/null_index.hpp>
  12. #include <boost/interprocess/managed_shared_memory.hpp>
  13. #include <boost/interprocess/mem_algo/simple_seq_fit.hpp>
  14. #include <cstddef>
  15. #include <cassert>
  16. #include <string>
  17. #include "get_process_id_name.hpp"
  18. using namespace boost::interprocess;
  19. typedef basic_managed_shared_memory
  20. <char, simple_seq_fit<mutex_family>, null_index>
  21. my_shared_objects_t;
  22. int main ()
  23. {
  24. //Create shared memory
  25. shared_memory_object::remove(test::get_process_id_name());
  26. {
  27. my_shared_objects_t segment
  28. (create_only,
  29. test::get_process_id_name(), //segment name
  30. 65536); //segment size in bytes
  31. //Allocate a portion of the segment
  32. void * shptr = segment.allocate(1024/*bytes to allocate*/);
  33. my_shared_objects_t::handle_t handle = segment.get_handle_from_address(shptr);
  34. if(!segment.belongs_to_segment(shptr)){
  35. return 1;
  36. }
  37. if(shptr != segment.get_address_from_handle(handle)){
  38. return 1;
  39. }
  40. segment.deallocate(shptr);
  41. }
  42. shared_memory_object::remove(test::get_process_id_name());
  43. return 0;
  44. }
  45. #include <boost/interprocess/detail/config_end.hpp>