doc_anonymous_shared_memory.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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. //[doc_anonymous_shared_memory
  12. #include <boost/interprocess/anonymous_shared_memory.hpp>
  13. #include <boost/interprocess/mapped_region.hpp>
  14. #include <iostream>
  15. #include <cstring>
  16. int main ()
  17. {
  18. using namespace boost::interprocess;
  19. try{
  20. //Create an anonymous shared memory segment with size 1000
  21. mapped_region region(anonymous_shared_memory(1000));
  22. //Write all the memory to 1
  23. std::memset(region.get_address(), 1, region.get_size());
  24. //The segment is unmapped when "region" goes out of scope
  25. }
  26. catch(interprocess_exception &ex){
  27. std::cout << ex.what() << std::endl;
  28. return 1;
  29. }
  30. return 0;
  31. }
  32. //]
  33. #include <boost/interprocess/detail/config_end.hpp>