Boost C++ Libraries: Ticket #12494: Cannot expand vector in place using interprocess::allocator and interprocess::rbtree_best_fit https://svn.boost.org/trac10/ticket/12494 <p> When using reserve() on a <code>interprocess::vector</code> (synomyn for <code>container::vector</code>) inside a <code>interprocess::basic_managed_mapped_file</code> (using the default <code>interprocess::rbtree_best_fit</code> memory algorithm), it cannot in place expand forward. </p> <p> I noticed this when getting help on <a class="ext-link" href="https://stackoverflow.com/questions/39780787/boostmanaged-mapped-file-cannot-allocate-all-of-grown-space"><span class="icon">​</span>this</a> SO question. Using the code in that question, put a breakpoint at \boost\interprocess\mem_algo\rbtree_best_fit.hpp:964, and then trace the call stack back to <code>vector::priv_reserve_no_capacity(size_type new_cap, version_2)</code>: </p> <pre class="wiki">pointer reuse = 0; pointer const ret(this-&gt;m_holder.allocation_command(allocate_new | expand_fwd | expand_bwd, new_cap, real_cap = new_cap, reuse)); </pre><p> The <code>reuse</code> pointer is set to null, resumably so it can be overridden by the allocator. The pointer is passed up the stack to <code>interprocess::allocator::allocation_command(boost::interprocess::allocation_type command, size_type limit_size, size_type &amp;prefer_in_recvd_out_size, pointer &amp;reuse)</code> where the raw pointer is retrieved: </p> <pre class="wiki">value_type *reuse_raw = ipcdetail::to_raw_pointer(reuse); pointer const p = mp_mngr-&gt;allocation_command(command, limit_size, prefer_in_recvd_out_size, reuse_raw); </pre><p> <code>reuse_raw</code> continues to be passed up the stack to where our breakpoint is: </p> <pre class="wiki">//Expand in place prefer_in_recvd_out_size = preferred_size; if(reuse_ptr &amp;&amp; (command &amp; (boost::interprocess::expand_fwd | boost::interprocess::expand_bwd))){ void *ret = priv_expand_both_sides (command, limit_size, prefer_in_recvd_out_size, reuse_ptr, true, backwards_multiple); if(ret) return ret; } </pre><p> <code>reuse_ptr</code> is our raw pointer and is as null as it was when created, causing the expand in place block to be skipped. In short there appears to be no way for a vector to be in place expanded when used inside a memory mapped file. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12494 Trac 1.4.3 Ion Gaztañaga Mon, 06 Feb 2017 13:36:50 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/12494#comment:1 https://svn.boost.org/trac10/ticket/12494#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> Thanks for the report, but this issue was fixed in: </p> <p> <a class="ext-link" href="https://github.com/boostorg/container/commit/0b75df992019cd3ace25912f74b6d416926f4a22"><span class="icon">​</span>https://github.com/boostorg/container/commit/0b75df992019cd3ace25912f74b6d416926f4a22</a> </p> <p> and released in boost 1.62. </p> Ticket