Boost C++ Libraries: Ticket #4603: circular_buffer_space_optimized does not grow when capacity runs out https://svn.boost.org/trac10/ticket/4603 <p> Contrary to what the documentation specifies, circular_buffer_space_optimized does not grow when capacity runs out. </p> <p> The problem seems to be in line 1243 of space_optimized.hpp: </p> <div class="wiki-code"><div class="code"><pre><span class="mi">1239</span> <span class="c1">//! Ensure the reserve for possible growth up.</span> <span class="mi">1240</span> <span class="n">size_type</span> <span class="n">ensure_reserve</span><span class="p">(</span><span class="n">size_type</span> <span class="n">new_capacity</span><span class="p">,</span> <span class="n">size_type</span> <span class="n">buffer_size</span><span class="p">)</span> <span class="k">const</span> <span class="p">{</span> <span class="mi">1241</span> <span class="k">if</span> <span class="p">(</span><span class="n">buffer_size</span> <span class="o">+</span> <span class="n">new_capacity</span> <span class="o">/</span> <span class="mi">5</span> <span class="o">&gt;=</span> <span class="n">new_capacity</span><span class="p">)</span> <span class="mi">1242</span> <span class="n">new_capacity</span> <span class="o">*=</span> <span class="mi">2</span><span class="p">;</span> <span class="c1">// ensure at least 20% reserve</span> <span class="c1">/// shouldn&#39;t this be less-than?</span> <span class="mi">1243</span> <span class="nf">if</span> <span class="p">(</span><span class="n">new_capacity</span> <span class="o">&gt;</span> <span class="n">m_capacity_ctrl</span><span class="p">)</span> <span class="mi">1244</span> <span class="k">return</span> <span class="n">m_capacity_ctrl</span><span class="p">;</span> <span class="mi">1245</span> <span class="k">return</span> <span class="n">new_capacity</span><span class="p">;</span> <span class="mi">1246</span> <span class="p">}</span> </pre></div></div><p> I've tested changing the "greater-than" sign on line 1243 to a "less-than" and that works fine. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4603 Trac 1.4.3 anonymous Sat, 28 Aug 2010 21:01:52 GMT <link>https://svn.boost.org/trac10/ticket/4603#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4603#comment:1</guid> <description> <p> I believe the code is right. If you create a space optimized circular buffer of a particular capacity e.g. of 10 elements it's capacity should remain unchanged (unless it is changed explicitly). When you normally instantiate the space optimized buffer the allocated memory (internal capacity) is zero. As you fill the buffer with elements the internal capacity grows but upto 10 elements. When you insert more than 10 elements then the oldest elements get overwriten. (And vice versa if you remove the elemens from the buffer the allocated memory slowly decreases.) </p> <p> Hope this makes sense. </p> <p> Jan </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Jan Gaspar</dc:creator> <pubDate>Sat, 28 Aug 2010 21:04:31 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4603#comment:2 https://svn.boost.org/trac10/ticket/4603#comment:2 <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> Ticket