]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/interprocess/example/doc_offset_ptr.cpp
1 //////////////////////////////////////////////////////////////////////////////
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)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 #include <boost/interprocess/detail/workaround.hpp>
13 #include <boost/interprocess/managed_shared_memory.hpp>
14 #include <boost/interprocess/offset_ptr.hpp>
16 #include "../test/get_process_id_name.hpp"
19 using namespace boost::interprocess
;
21 //Shared memory linked list node
24 offset_ptr
<list_node
> next
;
30 //Remove shared memory on construction and destruction
35 shm_remove() { shared_memory_object::remove(test::get_process_id_name()); }
36 ~shm_remove(){ shared_memory_object::remove(test::get_process_id_name()); }
39 shm_remove() { shared_memory_object::remove("MySharedMemory"); }
40 ~shm_remove(){ shared_memory_object::remove("MySharedMemory"); }
49 //Create shared memory
52 managed_shared_memory
segment(create_only
,
53 test::get_process_id_name(), //segment name
57 managed_shared_memory
segment(create_only
,
58 "MySharedMemory", //segment name
64 //Create linked list with 10 nodes in shared memory
65 offset_ptr
<list_node
> prev
= 0, current
, first
;
68 for(i
= 0; i
< 10; ++i
, prev
= current
){
69 current
= static_cast<list_node
*>(segment
.allocate(sizeof(list_node
)));
79 //Communicate list to other processes
81 //When done, destroy list
82 for(current
= first
; current
; /**/){
84 current
= current
->next
;
85 segment
.deallocate(prev
.get());