SharedData.h
Go to the documentation of this file.
1 #ifndef SHAREDDATA__H
2 #define SHAREDDATA__H
3 #include <boost/interprocess/shared_memory_object.hpp>
4 #include <boost/interprocess/managed_shared_memory.hpp>
5 
6 template<class dataType>
7 class SharedData{
8  public:
9  SharedData(const char* shmem_name, const char* data_name):
10  fShmemName(shmem_name),
11  fSegment(boost::interprocess::open_or_create,shmem_name,sizeof(dataType)*2)
12  {
13  std::cout<<"sizeof(dataType)="<<sizeof(dataType)<<std::endl;
14  fData = fSegment.find_or_construct<dataType>(data_name)();
15  }
17  clearMem();
18  }
19  void clearMem(){
20  boost::interprocess::shared_memory_object::remove(fShmemName);
21  }
22  dataType& getData(){return *fData;}
23  const dataType& getData() const{return *fData;}
24  protected:
25  const char* fShmemName;
26  boost::interprocess::managed_shared_memory fSegment;
27  dataType* fData;
28 };
29 #endif
dataType * fData
Definition: SharedData.h:27
dataType & getData()
Definition: SharedData.h:22
const dataType & getData() const
Definition: SharedData.h:23
const char * fShmemName
Definition: SharedData.h:25
void clearMem()
Definition: SharedData.h:19
OStream cout
Definition: OStream.cxx:6
boost::interprocess::managed_shared_memory fSegment
Definition: SharedData.h:26
SharedData(const char *shmem_name, const char *data_name)
Definition: SharedData.h:9