1
//////////////////////////////////////////////////////////////////////////////
3
// (C) Copyright Ion Gaztanaga 2004-2011. 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)
7
// See http://www.boost.org/libs/interprocess for documentation.
9
//////////////////////////////////////////////////////////////////////////////
11
#include <boost/interprocess/detail/config_begin.hpp>
13
#ifdef BOOST_INTERPROCESS_WINDOWS
17
#include <boost/interprocess/windows_shared_memory.hpp>
18
#include <boost/interprocess/mapped_region.hpp>
20
#include "get_process_id_name.hpp"
22
using namespace boost::interprocess;
27
const char *names[2] = { test::get_process_id_name(), 0 };
28
for(unsigned int i = 0; i < sizeof(names)/sizeof(names[0]); ++i)
30
const std::size_t FileSize = 99999*2;
31
//Create a file mapping
32
windows_shared_memory mapping
33
(create_only, names[i], read_write, FileSize);
37
//Create two mapped regions, one half of the file each
38
mapped_region region (mapping
44
mapped_region region2(mapping
47
,FileSize - FileSize/2
50
//Fill two regions with a pattern
51
unsigned char *filler = static_cast<unsigned char*>(region.get_address());
55
*filler++ = static_cast<unsigned char>(i);
58
filler = static_cast<unsigned char*>(region2.get_address());
59
for(std::size_t i = FileSize/2
62
*filler++ = static_cast<unsigned char>(i);
66
//See if the pattern is correct in the file using two mapped regions
68
mapped_region region (mapping, read_only, 0, FileSize/2, 0);
69
mapped_region region2(mapping, read_only, FileSize/2, FileSize - FileSize/2, 0);
71
unsigned char *checker = static_cast<unsigned char*>(region.get_address());
76
if(*checker++ != static_cast<unsigned char>(i)){
82
checker = static_cast<unsigned char *>(region2.get_address());
85
for(std::size_t i = FileSize/2
88
if(*checker++ != static_cast<unsigned char>(i)){
94
//Now check the pattern mapping a single read only mapped_region
96
//Create a single regions, mapping all the file
97
mapped_region region (mapping, read_only);
100
unsigned char *pattern = static_cast<unsigned char*>(region.get_address());
101
for(std::size_t i = 0
104
if(*pattern != static_cast<unsigned char>(i)){
111
catch(std::exception &exc){
112
//shared_memory_object::remove(test::get_process_id_name());
113
std::cout << "Unhandled exception: " << exc.what() << std::endl;
129
#include <boost/interprocess/detail/config_end.hpp>