<div dir="ltr"><font style="vertical-align:inherit"><font style="vertical-align:inherit">Hi Andre, </font></font><div>.resize(0) actually deletes the storage.  

Farrakh is wanting it to preserve the storage (keep the .capacity(), not have to alloc it again)<br><div><br></div><div><font style="vertical-align:inherit"><font style="vertical-align:inherit">Farrakh,</font></font></div><div>I think that you might not realize the reason .clear() is slower is because it has to call the 

in-place

destructor for each element (zero through size(), but not all the way up to .capacity())  You can&#39;t just change the count or you screw up the object lifetime of those objects that were not destructed. D&#39;tors won&#39;t get called.  Index positions may potentially get overwritten later with subsequent push_backs(...) and the in-place c&#39;tors calls. (thus causing leaks)</div></div><div><br></div><div><a href="https://en.cppreference.com/w/cpp/container/vector/clear" target="_blank">https://en.cppreference.com/w/cpp/container/vector/clear</a></div></div><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Dec 27, 2024 at 2:08 PM Andre Kostur via Std-Proposals &lt;<a href="mailto:std-proposals@lists.isocpp.org" target="_blank">std-proposals@lists.isocpp.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">What’s wrong with .resize(0) ?</div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Dec 27, 2024 at 1:57 PM Фаррах Фаттахов via Std-Proposals &lt;<a href="mailto:std-proposals@lists.isocpp.org" target="_blank">std-proposals@lists.isocpp.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="direction:ltr;margin-top:1em;margin-bottom:1em;font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">After working with SFML, I so hated std::vector (I was a bad programmer back then and didn&#39;t know about the reserve() function, which led to not understanding why std::vector is so slow, while a simple array performs much better). As a result, in my new project i created my own version of std::vector - FE2D::dynamic_array. And there, from the beginning i created one useful function - reset()</div><div style="direction:ltr;margin-top:1em;margin-bottom:1em;font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">```C++</div><pre style="margin-top:0px;margin-bottom:0px;border-radius:6px;min-height:52px"><div style="direction:ltr;line-height:1.45;font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">// Reset the Size of Dynamic Array to Zero, but it&#39;s don&#39;t Touches the Real Occupied Memory of Dynamic Array
void reset() { mSize = 0; }</div><div style="direction:ltr;line-height:1.45;font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">```</div></pre><div style="direction:ltr;margin-top:0px;font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">Instead of clear() it&#39;s just setting mSize to zero. It&#39;s very useful in the situations like</div><pre style="margin-top:0px;margin-bottom:0px;border-radius:6px;min-height:52px"><div style="direction:ltr;line-height:1.45;font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">```C++</div><div style="direction:ltr;line-height:1.45;font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">void Render() { // It&#39;s called every frame
// Add a sprites to the FE2D::dynamic_array to draw it later
m_Renderer.AddSprite(m_Sprite_0);
m_Renderer.AddSprite(m_Sprite_1);
m_Renderer.AddSprite(m_Sprite_2);
...
// Draw the Sprites and reset the dynamic arrays to prepare it for the next frame
m_Renderer.RenderSprites();
}</div><div style="direction:ltr;line-height:1.45;font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">```<br>Here reset() works like clear(), but much faster</div></pre><div style="direction:ltr;margin-top:0px;margin-bottom:0px;font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">In the std::vector or std::deque is no functions like reset() and i want to add it there, especially sometimes i get errors because my FE2D::dynamic_array is not so good like std::vector and i have to use it instead of mine, but there is no function i need. I think reset() will be nice thing for std::vector.</div></div>
-- <br>
Std-Proposals mailing list<br>
<a href="mailto:Std-Proposals@lists.isocpp.org" target="_blank">Std-Proposals@lists.isocpp.org</a><br>
<a href="https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals" rel="noreferrer" target="_blank">https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals</a><br>
</blockquote></div></div>
-- <br>
Std-Proposals mailing list<br>
<a href="mailto:Std-Proposals@lists.isocpp.org" target="_blank">Std-Proposals@lists.isocpp.org</a><br>
<a href="https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals" rel="noreferrer" target="_blank">https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals</a><br>
</blockquote></div>

