<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[Gelöst] Vector::push_back - &amp;quot;free space&amp;quot; anpassen]]></title><description><![CDATA[<p>Hallöchen,</p>
<p>ich implementiere gerade mit einem Buch eine Kopie des std::vector (oder etwas ähnliches) und bin nun bei push_back angelangt.</p>
<p>Das ist so dargestellt:</p>
<pre><code>void Vector::push_back(double d)
{
    if (!space) reserve(8);
    else if (sz == space) reserve(2 * space);
    elem[sz] = d;
    ++sz;
}
</code></pre>
<p>Scheint erstmal ganz logisch zu sein. Aber dann frage ich mich: Wenn ich die Größe um 1 erhöhe, muss ich dann nicht den noch freien Platz um 1 verringern? Also ca. so:</p>
<pre><code>void Vector::push_back(double d)
{
    if (!space) reserve(8);
    else if (sz == space) reserve(2 * space);
    elem[sz] = d;
    ++sz;
    --space;  // Ein freier Platz weniger
}
</code></pre>
<p>Würd mich freuen, wenn mich jemand da aufklärt.</p>
<p>lg</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/330700/gelöst-vector-push_back-quot-free-space-quot-anpassen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 02 Jul 2026 22:50:32 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/330700.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 22 Jan 2015 14:14:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Gelöst] Vector::push_back - &amp;quot;free space&amp;quot; anpassen on Thu, 22 Jan 2015 15:50:17 GMT]]></title><description><![CDATA[<p>Hallöchen,</p>
<p>ich implementiere gerade mit einem Buch eine Kopie des std::vector (oder etwas ähnliches) und bin nun bei push_back angelangt.</p>
<p>Das ist so dargestellt:</p>
<pre><code>void Vector::push_back(double d)
{
    if (!space) reserve(8);
    else if (sz == space) reserve(2 * space);
    elem[sz] = d;
    ++sz;
}
</code></pre>
<p>Scheint erstmal ganz logisch zu sein. Aber dann frage ich mich: Wenn ich die Größe um 1 erhöhe, muss ich dann nicht den noch freien Platz um 1 verringern? Also ca. so:</p>
<pre><code>void Vector::push_back(double d)
{
    if (!space) reserve(8);
    else if (sz == space) reserve(2 * space);
    elem[sz] = d;
    ++sz;
    --space;  // Ein freier Platz weniger
}
</code></pre>
<p>Würd mich freuen, wenn mich jemand da aufklärt.</p>
<p>lg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2439048</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2439048</guid><dc:creator><![CDATA[HarteWare]]></dc:creator><pubDate>Thu, 22 Jan 2015 15:50:17 GMT</pubDate></item><item><title><![CDATA[Reply to [Gelöst] Vector::push_back - &amp;quot;free space&amp;quot; anpassen on Thu, 22 Jan 2015 14:21:09 GMT]]></title><description><![CDATA[<p>space ist in deinem Fall, wenn ich das richtig verstehe, nicht der freie Platz sondern der absolut verfügbare. Daher wohl sicherlich nicht. Aber ohne den Code zu kennen kann man dies nicht wirklich sagen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2439050</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2439050</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Thu, 22 Jan 2015 14:21:09 GMT</pubDate></item><item><title><![CDATA[Reply to [Gelöst] Vector::push_back - &amp;quot;free space&amp;quot; anpassen on Thu, 22 Jan 2015 14:31:05 GMT]]></title><description><![CDATA[<p>Beim Programmieren sind passende Namen sehr wichtig.</p>
<p>Die richtigen Namen wären size/capacity anstatt sz/space.<br />
Dann ist klar, was sie bedeuten: size ist die Anzahl belegter Plätze, capacity ist die gesamte Anzahl Plätze, belegt und frei.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2439052</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2439052</guid><dc:creator><![CDATA[namser]]></dc:creator><pubDate>Thu, 22 Jan 2015 14:31:05 GMT</pubDate></item><item><title><![CDATA[Reply to [Gelöst] Vector::push_back - &amp;quot;free space&amp;quot; anpassen on Thu, 22 Jan 2015 15:21:38 GMT]]></title><description><![CDATA[<p>danke Leute, ich glaub das ist es, hab ich ein Denkfehler.<br />
lg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2439064</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2439064</guid><dc:creator><![CDATA[HarteWare]]></dc:creator><pubDate>Thu, 22 Jan 2015 15:21:38 GMT</pubDate></item></channel></rss>