我使用一個boost ::進程間:: managed_external_buffer,並試圖在特定地址來創建這樣一個緩衝的時候,我得到以下錯誤(斷言失敗):內存對齊約束
/homes/mdorier/local/include/boost/interprocess/managed_external_buffer.hpp:67: 的boost ::進程間:: basic_managed_external_buffer :: basic_managed_external_buffer(升壓::進程間:: create_only_t, 無效*,類型名 的boost :: interprocess :: ipcdetail :: basic_managed_memory_impl :: size_type)[CharType = char,AllocationAlgorithm = boost :: interprocess :: r (AllocationAlgorithm :: Alignment-size_type(1u))))'failed。(0, ==(((std :: size_t)addr)&(AllocationAlgorithm :: Alignment-size_type(1u))))'failed。
線67 managed_external_buffer.hpp對應下面的函數來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");
}
}
我的代碼工作正常,在Ubuntu的i686的使用GCC 4.6.2。上面的錯誤出現在使用GCC 4.4.3的Ubuntu x86_64上。
任何想法,爲什麼在一個平臺上,我沒有得到任何錯誤,而內存對齊似乎在另一個問題上?
如果managed_external_buffer要我調整地址,我很好,但我應該知道至少應該提供什麼值。我怎樣才能做到這一點?
謝謝
這取決於'AllocationAlgorithm :: Alignment'是什麼。您可以隨時在調試器中斷開並查看預期值。或者,它只有幾次嘗試 - 8或16(最有可能),32或64.對於SIMD相關的數據類型,它可能是128,但我懷疑Boost傢伙是否斷言。 – 2012-08-22 21:33:05
事實上,有16個工作。非常感謝你! – sunmat