| 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 | //[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 | |
| 17 | int main () |
| 18 | { |
| 19 | using namespace boost::interprocess; |
| 20 | BOOST_TRY{ |
| 21 | //Create an anonymous shared memory segment with size 1000 |
| 22 | mapped_region region(anonymous_shared_memory(size: 1000)); |
| 23 | |
| 24 | //Write all the memory to 1 |
| 25 | std::memset(s: region.get_address(), c: 1, n: region.get_size()); |
| 26 | |
| 27 | //The segment is unmapped when "region" goes out of scope |
| 28 | } |
| 29 | BOOST_CATCH(interprocess_exception &ex){ |
| 30 | std::cout << ex.what() << std::endl; |
| 31 | return 1; |
| 32 | } BOOST_CATCH_END |
| 33 | return 0; |
| 34 | } |
| 35 | //] |
| 36 | |
| 37 |
