title: C++ Boost::Interprocess Shared memory with struct
body: <p>I search to shared a struct between two process. But I have not success.Can you help to understand ? </p>
  
  <p>Here is my code for first process : </p>
  
  <pre><code>#include &lt;boost/interprocess/sync/interprocess_semaphore.hpp&gt;
  #include &lt;boost/interprocess/shared_memory_object.hpp&gt;
  #include &lt;boost/interprocess/mapped_region.hpp&gt;
  #include &lt;boost/interprocess/managed_shared_memory.hpp&gt;
  #include &lt;boost/interprocess/containers/vector.hpp&gt;
  #include &lt;boost/interprocess/containers/string.hpp&gt;
  #include &lt;boost/interprocess/allocators/allocator.hpp&gt;
  #include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string&gt;
  #include &lt;time.h&gt;
  #include "semaphore_shared_data.hpp"
  
  using namespace boost::interprocess;
  
  
  int main(){
  
  shared_memory_object shm(open_or_create, "shared_memory", read_write);
  shm.truncate(sizeof(shared_memory_buffer));
  mapped_region region(shm,read_write);
  
  void *addr = region.get_address();
  shared_memory_buffer *data = new (addr) shared_memory_buffer;
  while(true){
  
     data-&gt;writer.wait();
     std::cout &lt;&lt; "Process 1 read: " &lt;&lt; data-&gt;Variable.Type &lt;&lt; ":" &lt;&lt;data-&gt;Variable.Value &lt;&lt; std::endl;
  
    data-&gt;Variable.Type = "ACK";
    data-&gt;Variable.Value = 1;
    sleep(1);
    data-&gt;reader.post();
  }
  return 0;
  }
  </code></pre>
  
  <p>Here is my code for second process : </p>
  
  <pre><code>#include &lt;boost/interprocess/shared_memory_object.hpp&gt;
  #include &lt;boost/interprocess/mapped_region.hpp&gt;
  #include &lt;boost/interprocess/managed_shared_memory.hpp&gt;
  #include &lt;boost/interprocess/containers/vector.hpp&gt;
  #include &lt;boost/interprocess/containers/string.hpp&gt;
  #include &lt;boost/interprocess/allocators/allocator.hpp&gt;
  #include &lt;boost/interprocess/sync/interprocess_semaphore.hpp&gt;
  #include &lt;iostream&gt;
  #include &lt;math.h&gt;
  #include &lt;string&gt;
  #include "semaphore_shared_data.hpp"
  
  using namespace boost::interprocess;
  
  
  int main ()
  {
  
   shared_memory_object shm(open_only, "shared_memory",read_write);
   mapped_region region(shm,read_write);
   void *addr = region.get_address();
  
   shared_memory_buffer *data = static_cast&lt;shared_memory_buffer*&gt;(addr);
   while(true)
   {
  
     data-&gt;reader.wait();
     std::cout &lt;&lt; "Process 2 read: " &lt;&lt; data-&gt;Variable.Type &lt;&lt; ":" &lt;&lt;    data-&gt;Variable.Value &lt;&lt; std::endl;
     data-&gt;Variable.Type = "ACK";
     data-&gt;Variable.Value = 2;
     data-&gt;writer.post();
   }
   return 0;
  }
  </code></pre>
  
  <p>here is my code for shared_memory_buffer (semaphore_shared_data.hpp)</p>
  
  <pre><code>#include &lt;boost/interprocess/sync/interprocess_semaphore.hpp&gt;
  #include &lt;boost/interprocess/managed_shared_memory.hpp&gt;
  #include &lt;boost/interprocess/containers/vector.hpp&gt;
  #include &lt;boost/interprocess/containers/string.hpp&gt;
  #include &lt;boost/interprocess/allocators/allocator.hpp&gt;
  #include &lt;string&gt;
  using namespace boost::interprocess;
  
  typedef allocator&lt;char, managed_shared_memory::segment_manager&gt;  CharAllocator;
  typedef basic_string&lt;char, std::char_traits&lt;char&gt;, CharAllocator&gt;shared_string;
  
  struct shared_Struct
  {
    shared_Struct():Type("ACK"), Value(0){}
    shared_string Type;
    float Value;
  
  };
  
  struct shared_memory_buffer 
  {
  
     shared_memory_buffer(): writer(1), reader(0), Variable(){}
     interprocess_semaphore writer, reader;
  
     shared_Struct Variable;
  
  };
  </code></pre>
  
  <p>I have this errors : </p>
  
  <pre><code>semaphore_shared_data.hpp: In constructor ‘boost::container::basic_string&lt;CharT, Traits, Allocator&gt;::basic_string(const CharT*, const allocator_type&amp;) [with CharT = char; Traits = std::char_traits&lt;char&gt;; Allocator = boost::interprocess::allocator&lt;char, boost::interprocess::segment_manager&lt;char, boost::interprocess::rbtree_best_fit&lt;boost::interprocess::mutex_family&gt;, boost::interprocess::iset_index&gt; &gt;; boost::container::basic_string&lt;CharT, Traits, Allocator&gt;::allocator_type = boost::interprocess::allocator&lt;char, boost::interprocess::segment_manager&lt;char, boost::interprocess::rbtree_best_fit&lt;boost::interprocess::mutex_family&gt;, boost::interprocess::iset_index&gt; &gt;]’:
  
  semaphore_shared_data.hpp:16:38: error: no matching function for call to ‘boost::interprocess::allocator&lt;char, boost::interprocess::segment_manager&lt;char, boost::interprocess::rbtree_best_fit&lt;boost::interprocess::mutex_family&gt;, boost::interprocess::iset_index&gt; &gt;::allocator()’ shared_Struct():Type("ACK"), Value(0){}
  </code></pre>