<?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[Speicherplatz eine std::vectors]]></title><description><![CDATA[<p>Wieviel Byte /Kbyte würde dieser Vector im Speicher benötigen?</p>
<pre><code class="language-cpp">std::vector&lt;std::pair&lt;CWorkEvent*,CWorkEvent*&gt; &gt; data(128,std::pair&lt;CWorkEvent*,CWorkEvent*&gt;(NULL,NULL));
</code></pre>
<p>ein Pointer hat ja 4Byte, davon ein Pair sind 8 Byte und das ganze<br />
128 mal sind 1Kbyte ... ist das möglich.. oder kommt da noch ne menge byte an Overhead hinzu?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/194698/speicherplatz-eine-std-vectors</link><generator>RSS for Node</generator><lastBuildDate>Tue, 29 Sep 2026 15:15:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/194698.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 10 Oct 2007 05:32:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Speicherplatz eine std::vectors on Wed, 10 Oct 2007 05:34:32 GMT]]></title><description><![CDATA[<p>Wieviel Byte /Kbyte würde dieser Vector im Speicher benötigen?</p>
<pre><code class="language-cpp">std::vector&lt;std::pair&lt;CWorkEvent*,CWorkEvent*&gt; &gt; data(128,std::pair&lt;CWorkEvent*,CWorkEvent*&gt;(NULL,NULL));
</code></pre>
<p>ein Pointer hat ja 4Byte, davon ein Pair sind 8 Byte und das ganze<br />
128 mal sind 1Kbyte ... ist das möglich.. oder kommt da noch ne menge byte an Overhead hinzu?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1381675</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1381675</guid><dc:creator><![CDATA[BorisDieKlinge]]></dc:creator><pubDate>Wed, 10 Oct 2007 05:34:32 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherplatz eine std::vectors on Wed, 10 Oct 2007 05:38:04 GMT]]></title><description><![CDATA[<p>Ein pair benötigt Platz für seine Elemente - also hier 2*sizeof(CWorkEvent*), dazu kommt im vector noch Platz für 2..3 Hilfszeiger und/oder -ints, also insgesamt ca. 128*2*sizeof(CWorkEvent*)+3*sizeof(void*). Bei einer Größe von 4 Byte für Zeiger hast du also 1036 Byte (etwas über ein KB).</p>
<p>Aber der vector kann seine Kapazität auch prophylaktisch etwas größer ansetzen, was zusätzlich Platz benötigt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1381677</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1381677</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 10 Oct 2007 05:38:04 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherplatz eine std::vectors on Wed, 10 Oct 2007 06:15:27 GMT]]></title><description><![CDATA[<p>dazu faellt mir grad ein,<br />
braucht ein vector den speicherplatz am stueck?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1381701</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1381701</guid><dc:creator><![CDATA[EXDW]]></dc:creator><pubDate>Wed, 10 Oct 2007 06:15:27 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherplatz eine std::vectors on Wed, 10 Oct 2007 06:22:45 GMT]]></title><description><![CDATA[<p>Den Platz für die Nutzdaten ja (ist afaik im Standard festgelegt, aber frag mich jetzt nicht nach dem entsprechenden Paragraphen). Der Platz für die internen Daten liegt extra (und ist klein genug, um auf den Stack zu passen).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1381704</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1381704</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 10 Oct 2007 06:22:45 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherplatz eine std::vectors on Wed, 10 Oct 2007 06:30:53 GMT]]></title><description><![CDATA[<p>und nochmal zu reserve:</p>
<pre><code class="language-cpp">std::vector&lt;std::pair&lt;CWorkEvent*,CWorkEvent*&gt; &gt; data(1,std::pair&lt;CWorkEvent*,CWorkEvent*&gt;(NULL,NULL));

data.reserve(128);
</code></pre>
<p>der Vector braucht nun trozdem ca. 1036kb?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1381710</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1381710</guid><dc:creator><![CDATA[BorisDieKlinge]]></dc:creator><pubDate>Wed, 10 Oct 2007 06:30:53 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherplatz eine std::vectors on Wed, 10 Oct 2007 06:34:15 GMT]]></title><description><![CDATA[<p>Ja, mindestens. reserve(cap) legt genug Platz an, um (irgendwann später) mindestens cap Elemente unterbringen zu können.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1381712</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1381712</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 10 Oct 2007 06:34:15 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherplatz eine std::vectors on Wed, 10 Oct 2007 06:51:04 GMT]]></title><description><![CDATA[<p>hmm dann ist es ja in diesem Fall egal, ob ich den vector direkt mit der größe anlege oder nich.. nachteil ist halt das er den ganzen vector komplett iterieren muss, auch wenn nur 3 elemente verwendent werden:)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1381724</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1381724</guid><dc:creator><![CDATA[BorisDieKlinge]]></dc:creator><pubDate>Wed, 10 Oct 2007 06:51:04 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherplatz eine std::vectors on Wed, 10 Oct 2007 06:53:59 GMT]]></title><description><![CDATA[<p>Wer muß den Vector iterieren? Wenn du nur drei Elemente hast, aber Platz für 100 reserviert hast, sind die übrigen 97*sizeof(T) Bytes nicht-initialisierter Datenmüll, der erst bei Bedarf aufgefüllt wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1381727</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1381727</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 10 Oct 2007 06:53:59 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherplatz eine std::vectors on Wed, 10 Oct 2007 07:13:01 GMT]]></title><description><![CDATA[<p>Der einzige Vorteil, den dir reserve() in dem Fall liefern kann ist der, dass sich der vector dann einmalig den nötigen Speicher unter den Nagel reißt und seine Elemente dort hinein umkopiert. Wenn du auf reserve() verzichtest und mit einerm Haufen push_backs nach und nach Elemente hinzufügst, wird er jedesmal, wenn die Kapazität überschritten wird, sich einen größeren Speicherblock reservieren und alles umkopieren müssen.</p>
<p>Dass der Speicher für die Nutzdaten am Stück sein muss, ist soweit afair dadurch festgelegt, dass laut Standard &amp;v[i] = &amp;v[0] + i sein muss.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1381736</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1381736</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Wed, 10 Oct 2007 07:13:01 GMT</pubDate></item></channel></rss>