title: shared memory vector<string>, allocating strings with 8 byte alignment in 32 bit
body: <p>I'm using boost shared memory to share data between 32bit and 64bit processes. </p>
  
  <p>Under 64bit everything works fine, but under 32bit I get a compilation error whenever I need to allocate new elements to a <code>vector&lt;string&gt;</code>. <code>string</code> alone works without problems, also no problems with <code>vector&lt;uint32_t&gt;</code>. It's really only the <code>vector&lt;string&gt;</code> that seems to be at odds:</p>
  
  <blockquote>
    <p>error C2718: 'boost::container::basic_string,MDSDATA::char_allocator>': actual parameter with requested alignment of 8 won't be aligned</p>
  </blockquote>
  
  <p>The shared memory is defined with alignment of <code>uint64_t</code> for 32bit-64bit compatibility:</p>
  
  <pre><code>namespace bipc = boost::interprocess;
  namespace bc = boost::container;
  typedef bipc::basic_managed_windows_shared_memory
       &lt;  char
       ,  bipc::rbtree_best_fit
          &lt;
              bipc::mutex_family,
              bipc::offset_ptr&lt;void, int32_t, uint64_t&gt;
          &gt;
       ,  bipc::iset_index
       &gt;                                                          managed_shm_type;
  
  typedef bc::scoped_allocator_adaptor&lt;bipc::allocator&lt;void, segment_manager_t&gt; &gt; void_allocator;
  typedef void_allocator::rebind&lt;char&gt;::other                     char_allocator;
  typedef bc::basic_string
          &lt;
              char,
              std::char_traits&lt;char&gt;,
              char_allocator
          &gt;                                                       char_string;
  typedef void_allocator::rebind&lt;char_string&gt;::other              string_allocator;
  typedef bc::vector&lt;char_string, string_allocator&gt;               string_vector;
  </code></pre>
  
  <p>I only get the compilation error whenever I add code that reallocates elements in the vector like <code>emplace_back()</code>, <code>resize()</code>, <code>insert()</code> etc. Like in the following piece of code:</p>
  
  <pre><code>string_vector &amp; list(segment-&gt;getListvectorReference());
  list.clear();                 // this works fine
  list.emplace_back("hello");   // this fails
  list.resize(20);              // this fails too
  </code></pre>
  
  <p>An important note is the following: If I remove the code that causes the compilation error in the 32bit build, I am able to create new elements of the vector from the 64bit side and read them correctly from 32bit. It's just the opposite direction (32bit allocating the strings) that doesn't work.</p>
  
  <hr>
  
  <p><strong>Update:</strong></p>
  
  <p>Following <a href="https://datastax-oss.atlassian.net/browse/CPP-341" rel="nofollow noreferrer">this post</a> and the <a href="https://github.com/datastax/cpp-driver/pull/281/commits/4d82640fe19601679b732e9896704028d1e7f5bf" rel="nofollow noreferrer">respective patch</a>, I came to the assumption that this might be an issue with the Microsoft Compiler in conjunction with <em>boost</em>. I'm using <em>Visual Studio 2015 Express Update 3</em>. This is also supported by the error message itself that points to the file <code>boost/move/detail/type_traits.hpp</code>. I have the gut-feel that there may be an easy patch available to fix this in boost. </p>
  
  <p>Unfortunately, my knowledge is not sufficient to come up with a patch that would fix this issue in boost. However, I'll give credit to anybody that is able to provide a solution.</p>
  
  <p>For the time being I can live with this bug since I realized that my software will never allocate these strings from the 32bit code.</p>
  
  <hr>
  
  <p><strong>Update 2:</strong>
  There was <a href="https://github.com/boostorg/interprocess/pull/33" rel="nofollow noreferrer">a fix applied</a> in boost 1.64 that has some relation to this issue.</p>