1//////////////////////////////////////////////////////////////////////////////
2//
3// (C) Copyright Ion Gaztanaga 2005-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/indexes/null_index.hpp>
12#include <boost/interprocess/managed_shared_memory.hpp>
13#include <boost/interprocess/mem_algo/simple_seq_fit.hpp>
14#include <cstddef>
15#include <cassert>
16#include <string>
17#include "get_process_id_name.hpp"
18
19using namespace boost::interprocess;
20typedef basic_managed_shared_memory
21 <char, simple_seq_fit<mutex_family>, null_index>
22my_shared_objects_t;
23
24int main ()
25{
26 //Create shared memory
27 shared_memory_object::remove(filename: test::get_process_id_name());
28 {
29 my_shared_objects_t segment
30 (create_only,
31 test::get_process_id_name(), //segment name
32 65536); //segment size in bytes
33
34 //Allocate a portion of the segment
35 void * shptr = segment.allocate(nbytes: 1024/*bytes to allocate*/);
36 my_shared_objects_t::handle_t handle = segment.get_handle_from_address(ptr: shptr);
37 if(!segment.belongs_to_segment(ptr: shptr)){
38 return 1;
39 }
40 if(shptr != segment.get_address_from_handle(offset: handle)){
41 return 1;
42 }
43
44 segment.deallocate(addr: shptr);
45 }
46 shared_memory_object::remove(filename: test::get_process_id_name());
47 return 0;
48}
49

source code of boost/libs/interprocess/test/null_index_test.cpp