0
votes

I'm using a boost::interprocess::managed_external_buffer and, when trying to create such a buffer at a particular address, I get the following error (assertion failing):

/homes/mdorier/local/include/boost/interprocess/managed_external_buffer.hpp:67: boost::interprocess::basic_managed_external_buffer::basic_managed_external_buffer(boost::interprocess::create_only_t, void*, typename boost::interprocess::ipcdetail::basic_managed_memory_impl::size_type) [with CharType = char, AllocationAlgorithm = boost::interprocess::rbtree_best_fit, 0ul>, IndexType = boost::interprocess::iset_index]: Assertion `(0 == (((std::size_t)addr) & (AllocationAlgorithm::Alignment - size_type(1u))))' failed.

The line 67 in managed_external_buffer.hpp corresponds to BOOST_ASSERT statement in the following function:

//!Creates and places the segment manager. This can throw
   basic_managed_external_buffer
      (create_only_t, void *addr, size_type size)
   {
      //Check if alignment is correct
      BOOST_ASSERT((0 == (((std::size_t)addr) & (AllocationAlgorithm::Alignment - size_type(1u)))));
      if(!base_t::create_impl(addr, size)){
         throw interprocess_exception("Could not initialize buffer in basic_managed_external_buffer constructor");
      }
   }

My code works fine on a Ubuntu i686 with GCC 4.6.2. The error above appear on an Ubuntu x86_64 with GCC 4.4.3.

Any idea why on one platform I don't get any error while the memory alignment seems to matter on another one?

If the managed_external_buffer wants me to align the address, I'm fine with that, but I should know at least what value to provide. How can I do that?

Thank you

1
It depends on what AllocationAlgorithm::Alignment is. You can always break in debugger and see the expected value. Alternatively, it is only a few tries — 8 or 16 (most likely), 32 or 64. For SIMD-related data types it could be 128 but I doubt Boost guys are asserting for that. - user405725
Indeed, 16 worked. Thank you very much! - sunmat

1 Answers

3
votes

It looks like it is checking for natural pointe alignment.

So on a 32-bit platform it needs 4 byte alignment, whereas the 64 bit platform is checking for 8 byte alignment.

Some architectures are very unforgiving of misalignment of data types with memory addresses.