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