CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
WriteBuffer.h
Go to the documentation of this file.
1 #ifndef FWCore_SharedMemory_WriteBuffer_h
2 #define FWCore_SharedMemory_WriteBuffer_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/SharedMemory
6 // Class : WriteBuffer
7 //
17 //
18 // Original Author: Chris Jones
19 // Created: 21/01/2020
20 //
21 
22 // system include files
23 #include <array>
24 #include <memory>
25 #include <string>
26 #include <cassert>
27 #include <algorithm>
28 #include "boost/interprocess/managed_shared_memory.hpp"
29 
30 // user include files
33 
34 // forward declarations
35 
36 namespace edm::shared_memory {
37  class WriteBuffer {
38  public:
43  WriteBuffer(std::string const& iUniqueName, BufferInfo* iBufferInfo)
44  : bufferSize_{0}, buffer_{nullptr}, bufferInfo_{iBufferInfo} {
45  bufferNames_[0] = iUniqueName + buffer_names::kBuffer0;
46  bufferNames_[1] = iUniqueName + buffer_names::kBuffer1;
48  }
49  WriteBuffer(const WriteBuffer&) = delete;
50  const WriteBuffer& operator=(const WriteBuffer&) = delete;
51  WriteBuffer(WriteBuffer&&) = delete;
52  const WriteBuffer& operator=(WriteBuffer&&) = delete;
53 
54  ~WriteBuffer();
55 
56  // ---------- member functions ---------------------------
57  void copyToBuffer(const char* iStart, std::size_t iLength) {
58  if (iLength > bufferSize_) {
59  growBuffer(iLength);
60  }
61  std::copy(iStart, iStart + iLength, buffer_);
62  }
63 
64  private:
65  void growBuffer(std::size_t iLength);
66 
67  // ---------- member data --------------------------------
68  std::size_t bufferSize_;
69  char* buffer_;
71  std::array<std::string, 2> bufferNames_;
72  std::unique_ptr<boost::interprocess::managed_shared_memory> sm_;
73  };
74 } // namespace edm::shared_memory
75 
76 #endif
constexpr char const *const kBuffer0
Definition: buffer_names.h:30
assert(be >=bs)
void growBuffer(std::size_t iLength)
Definition: WriteBuffer.cc:41
std::array< std::string, 2 > bufferNames_
Definition: WriteBuffer.h:71
const WriteBuffer & operator=(const WriteBuffer &)=delete
constexpr char const *const kBuffer1
Definition: buffer_names.h:31
WriteBuffer(std::string const &iUniqueName, BufferInfo *iBufferInfo)
Definition: WriteBuffer.h:43
void copyToBuffer(const char *iStart, std::size_t iLength)
Definition: WriteBuffer.h:57
std::unique_ptr< boost::interprocess::managed_shared_memory > sm_
Definition: WriteBuffer.h:72