]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/interprocess/test/anonymous_shared_memory_test.cpp
cdff6e66fbb310d8cc5e2edafe1faf189e8e7a65
[ceph.git] / ceph / src / boost / libs / interprocess / test / anonymous_shared_memory_test.cpp
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 <boost/interprocess/detail/config_begin.hpp>
12 #include <iostream>
13 #include <boost/interprocess/mapped_region.hpp>
14 #include <boost/interprocess/anonymous_shared_memory.hpp>
15 #include <cstddef>
16 #include <exception>
17
18 using namespace boost::interprocess;
19
20 int main ()
21 {
22 try{
23 const std::size_t MemSize = 99999*2;
24 {
25 //Now check anonymous mapping
26 mapped_region region(anonymous_shared_memory(MemSize));
27
28 //Write pattern
29 unsigned char *pattern = static_cast<unsigned char*>(region.get_address());
30 for(std::size_t i = 0
31 ;i < MemSize
32 ;++i, ++pattern){
33 *pattern = static_cast<unsigned char>(i);
34 }
35
36 //Check pattern
37 pattern = static_cast<unsigned char*>(region.get_address());
38 for(std::size_t i = 0
39 ;i < MemSize
40 ;++i, ++pattern){
41 if(*pattern != static_cast<unsigned char>(i)){
42 return 1;
43 }
44 }
45 }
46 }
47 catch(std::exception &exc){
48 std::cout << "Unhandled exception: " << exc.what() << std::endl;
49 return 1;
50 }
51 return 0;
52 }
53
54 #include <boost/interprocess/detail/config_end.hpp>