1 | ////////////////////////////////////////////////////////////////////////////// |
---|---|
2 | // |
3 | // (C) Copyright Ion Gaztanaga 2004-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 | #include <iostream> |
12 | #include <boost/interprocess/mapped_region.hpp> |
13 | #include <boost/interprocess/anonymous_shared_memory.hpp> |
14 | #include <cstddef> |
15 | #include <exception> |
16 | |
17 | using namespace boost::interprocess; |
18 | |
19 | int main () |
20 | { |
21 | BOOST_TRY{ |
22 | const std::size_t MemSize = 99999*2; |
23 | { |
24 | //Now check anonymous mapping |
25 | mapped_region region(anonymous_shared_memory(size: MemSize)); |
26 | |
27 | //Write pattern |
28 | unsigned char *pattern = static_cast<unsigned char*>(region.get_address()); |
29 | for(std::size_t i = 0 |
30 | ;i < MemSize |
31 | ;++i, ++pattern){ |
32 | *pattern = static_cast<unsigned char>(i); |
33 | } |
34 | |
35 | //Check pattern |
36 | pattern = static_cast<unsigned char*>(region.get_address()); |
37 | for(std::size_t i = 0 |
38 | ;i < MemSize |
39 | ;++i, ++pattern){ |
40 | if(*pattern != static_cast<unsigned char>(i)){ |
41 | return 1; |
42 | } |
43 | } |
44 | } |
45 | } |
46 | BOOST_CATCH(std::exception &exc){ |
47 | std::cout << "Unhandled exception: "<< exc.what() << std::endl; |
48 | return 1; |
49 | } BOOST_CATCH_END |
50 | return 0; |
51 | } |
52 |