【发布时间】:2012-08-18 08:57:47
【问题描述】:
我正在使用 boost::interprocess::managed_external_buffer,当尝试在特定地址创建这样的缓冲区时,我收到以下错误(断言失败):
/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, 无效*,类型名 boost::interprocess::ipcdetail::basic_managed_memory_impl::size_type) [with CharType = 字符,分配算法 = boost::interprocess::rbtree_best_fit, 0ul>, IndexType = boost::interprocess::iset_index]: 断言`(0 == (((std::size_t)addr) & (AllocationAlgorithm::Alignment - size_type(1u))))' 失败。
managed_external_buffer.hpp 中的第 67 行对应以下函数中的 BOOST_ASSERT 语句:
//!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");
}
}
我的代码在带有 GCC 4.6.2 的 Ubuntu i686 上运行良好。上面的错误出现在带有 GCC 4.4.3 的 Ubuntu x86_64 上。
知道为什么在一个平台上我没有收到任何错误,而内存对齐在另一个平台上似乎很重要吗?
如果 managed_external_buffer 想要我对齐地址,我可以接受,但我至少应该知道要提供什么值。我该怎么做?
谢谢
【问题讨论】:
-
这取决于
AllocationAlgorithm::Alignment是什么。您可以随时中断调试器并查看预期值。或者,它只是几次尝试——8 或 16(最有可能)、32 或 64。对于与 SIMD 相关的数据类型,它可能是 128,但我怀疑 Boost 家伙是否会为此断言。 -
确实,16 个工作。非常感谢!
标签: c++ memory boost alignment