<?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[Array oder std::vector?]]></title><description><![CDATA[<p>Verwendet ihr einfache Arrays oder immer std::vector?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/150836/array-oder-std-vector</link><generator>RSS for Node</generator><lastBuildDate>Sun, 06 Sep 2026 01:28:21 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/150836.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 20 Jun 2006 17:44:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Array oder std::vector? on Tue, 20 Jun 2006 17:44:10 GMT]]></title><description><![CDATA[<p>Verwendet ihr einfache Arrays oder immer std::vector?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081573</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081573</guid><dc:creator><![CDATA[QuestionFrager]]></dc:creator><pubDate>Tue, 20 Jun 2006 17:44:10 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Tue, 20 Jun 2006 17:50:28 GMT]]></title><description><![CDATA[<p>wenn's kein std::vector sein muss, nehm ich n array, ansonsten halt nen std::vector.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081577</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081577</guid><dc:creator><![CDATA[GPC]]></dc:creator><pubDate>Tue, 20 Jun 2006 17:50:28 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Tue, 20 Jun 2006 17:50:41 GMT]]></title><description><![CDATA[<p>Da kriegste keine definitive Antwort, weils einfach vom verwendungszweck abhängt. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081578</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081578</guid><dc:creator><![CDATA[bluecode]]></dc:creator><pubDate>Tue, 20 Jun 2006 17:50:41 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Tue, 20 Jun 2006 18:09:02 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Ich muss ehrlich sagen, dass ich immer std::vector verwende, weil ich damit einfach besser klarkomme und noch keinen Nachteil kenne. (Ich lasse mich aber gerne aufklären.)</p>
<p>chrische</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081594</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081594</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Tue, 20 Jun 2006 18:09:02 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Tue, 20 Jun 2006 18:10:18 GMT]]></title><description><![CDATA[<p>Rohes Array braucht man nie, denn es gibt ja noch boost::array <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081595</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081595</guid><dc:creator><![CDATA[.,.]]></dc:creator><pubDate>Tue, 20 Jun 2006 18:10:18 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Tue, 20 Jun 2006 19:23:21 GMT]]></title><description><![CDATA[<p>Naja, nicht nur in Boost. Im TR1 gibts sogar std::tr1::array. Nie wieder rohe Arrays! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> Aber als Übergang kann man natürlich boost::array benutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081650</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081650</guid><dc:creator><![CDATA[Artchi]]></dc:creator><pubDate>Tue, 20 Jun 2006 19:23:21 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Tue, 20 Jun 2006 19:39:26 GMT]]></title><description><![CDATA[<p>chrische5 schrieb:</p>
<blockquote>
<p>Ich muss ehrlich sagen, dass ich immer std::vector verwende, weil ich damit einfach besser klarkomme und noch keinen Nachteil kenne. (Ich lasse mich aber gerne aufklären.)</p>
</blockquote>
<p>Kommt sicherlich auf die Implementierung an und auch was man mit dem Container &quot;aussagen&quot; will. Denn Code soll ja auch sprechend sein.</p>
<p>std::vector von Dinkumware reserviert am Anfang nur soviel wie auch drin ist. Packt man also ein Element rein, verbraucht Dinkumwares vector auch nur Platz für ein Array-Element. Macht also ggü. z.B. boost::array keinen Nachteil. Andere Implementierungen könnten z.B. 64 Elemente vorreservieren, selbst wenn nichts drin ist. Kann sich auf Systemen mit wenig Speicher schon summieren.</p>
<p>Ein Array hat aber eine feste Größe. boost::array ist z.B. in der Größe nicht änderbar, hat aber ansonst den Komfort eines Vectors. Wenn man weiß, das man kein dynamisches Array benötigt, muß man trotzdem kein C-Array nehmen. Benutzt einfach brav Boost oder bald tr1.</p>
<p>Achja, beim boost::array und std::tr1::array kann man sowas machen:</p>
<pre><code class="language-cpp">array&lt;int, 3&gt; a = {1,2,3};
</code></pre>
<p>Ist doch auch was, oder? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081654</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081654</guid><dc:creator><![CDATA[Artchi]]></dc:creator><pubDate>Tue, 20 Jun 2006 19:39:26 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Tue, 20 Jun 2006 19:40:00 GMT]]></title><description><![CDATA[<p>boost ist aber nicht im standard enthalten, oder?</p>
<p>Würdet ihr für Bilddaten auch den std::vector nehmen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081656</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081656</guid><dc:creator><![CDATA[QuestionFrager]]></dc:creator><pubDate>Tue, 20 Jun 2006 19:40:00 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Tue, 20 Jun 2006 20:16:51 GMT]]></title><description><![CDATA[<p>Artchi schrieb:</p>
<blockquote>
<pre><code class="language-cpp">array&lt;int, 3&gt; a = {1,2,3};
</code></pre>
</blockquote>
<p>Sorry, wenns nicht hierher gehört, aber wie ist das denn implementiert. Sprich welche Operatoren muss man für sowas überladen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081689</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081689</guid><dc:creator><![CDATA[bluecode]]></dc:creator><pubDate>Tue, 20 Jun 2006 20:16:51 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Tue, 20 Jun 2006 20:46:08 GMT]]></title><description><![CDATA[<p>bluecode schrieb:</p>
<blockquote>
<p>Artchi schrieb:</p>
<blockquote>
<pre><code class="language-cpp">array&lt;int, 3&gt; a = {1,2,3};
</code></pre>
</blockquote>
<p>Sorry, wenns nicht hierher gehört, aber wie ist das denn implementiert. Sprich welche Operatoren muss man für sowas überladen?</p>
</blockquote>
<p>Schau's dir an. Steht in den Headerdateien.</p>
<blockquote>
<p>Würdet ihr für Bilddaten auch den std::vector nehmen?</p>
</blockquote>
<p>ja</p>
<p>mfg.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081702</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081702</guid><dc:creator><![CDATA[joomoo]]></dc:creator><pubDate>Tue, 20 Jun 2006 20:46:08 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Wed, 21 Jun 2006 15:31:47 GMT]]></title><description><![CDATA[<p>bluecode schrieb:</p>
<blockquote>
<p>Sorry, wenns nicht hierher gehört, aber wie ist das denn implementiert. Sprich welche Operatoren muss man für sowas überladen?</p>
</blockquote>
<p>keine <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /> Das ist ein alter Trick</p>
<pre><code class="language-cpp">struct B
{
	int a, b, c;
};

struct X
{
	B b1;
	int i;
	B b2[2];
};

int main()
{

	B b = 
	{
		1,						//a
		2,						//b
		3						//c
	};

	X x = 
	{
		{1, 2, 3},				//b1
		4,						//i
		{{5, 6, 7}, {8, 9, 10}}	//b2
	};

	x;

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1082204</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082204</guid><dc:creator><![CDATA[ssm]]></dc:creator><pubDate>Wed, 21 Jun 2006 15:31:47 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Wed, 21 Jun 2006 16:25:02 GMT]]></title><description><![CDATA[<p>das geht, weil boost::array ein aggregat ist. dafür muss es auf einen selbstdefinierten konstruktor und destruktor verzichten, was dazu führt, dass boost::array nur fast ein container im sinne der standard bibliothek ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082252</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082252</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 21 Jun 2006 16:25:02 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Wed, 21 Jun 2006 20:53:07 GMT]]></title><description><![CDATA[<p>Übertreibe ich jetzt oder bin ich rückständig?</p>
<p>Wieso zum Teufel nehmt ihr für Arrays std::vector oder boost::array. Bald kommt bestimmt boost::bool.</p>
<p>Ich finde normale Arrays da einfach praktischer.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082528</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082528</guid><dc:creator><![CDATA[_42]]></dc:creator><pubDate>Wed, 21 Jun 2006 20:53:07 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Wed, 21 Jun 2006 21:04:57 GMT]]></title><description><![CDATA[<p>_42 schrieb:</p>
<blockquote>
<p>Wieso zum Teufel nehmt ihr für Arrays std::vector oder boost::array. Bald kommt bestimmt boost::bool.</p>
</blockquote>
<p>Haha, sehr gut <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Nimm für Bilddaten bitte normale arrays!! Da kannst du dann auch einfach mit read binary Daten reinlesen!</p>
<pre><code class="language-cpp">m_image = new char[dim_x*dim_y];
	FileBin.read(m_image , FileSize);
	FileBin.close();
</code></pre>
<p>Grüße vom boost:void*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082534</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082534</guid><dc:creator><![CDATA[Gast25250]]></dc:creator><pubDate>Wed, 21 Jun 2006 21:04:57 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Wed, 21 Jun 2006 21:12:36 GMT]]></title><description><![CDATA[<blockquote>
<p>Bald kommt bestimmt boost::bool.</p>
</blockquote>
<p>Wieso kommt noch? Gibts doch schon! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p><a href="http://www.boost.org/doc/html/tribool.html" rel="nofollow">http://www.boost.org/doc/html/tribool.html</a></p>
<p>:p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082539</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082539</guid><dc:creator><![CDATA[Artchi]]></dc:creator><pubDate>Wed, 21 Jun 2006 21:12:36 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Wed, 21 Jun 2006 21:31:45 GMT]]></title><description><![CDATA[<p>Gast25250 schrieb:</p>
<blockquote>
<p>_42 schrieb:</p>
<blockquote>
<p>Wieso zum Teufel nehmt ihr für Arrays std::vector oder boost::array. Bald kommt bestimmt boost::bool.</p>
</blockquote>
<p>Haha, sehr gut <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Nimm für Bilddaten bitte normale arrays!! Da kannst du dann auch einfach mit read binary Daten reinlesen!</p>
<pre><code class="language-cpp">m_image = new char[dim_x*dim_y];
	FileBin.read(m_image , FileSize);
	FileBin.close();
</code></pre>
<p>Grüße vom boost:void*</p>
</blockquote>
<p>Nix da <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> Das geht auch mit std::vector:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;vector&gt;
#include &lt;cassert&gt;

int main()
{
    std::vector&lt;char&gt; image;
    std::ifstream file(&quot;asd.bmp&quot;, std::ios::ate | std::ios::binary);
    assert(file);
    unsigned int filesize = file.tellg();
    file.seekg(0);
    // ...
    image.reserve(filesize);
    file.read(&amp;image[0], filesize);
    // ...
    std::ofstream fout(&quot;copy.bmp&quot;, std::ios::binary);
    assert(file);
    fout.write(&amp;image[0], filesize);
}
</code></pre>
<p>Und hierbei lässt sich nicht so leicht ein delete[] vergessen.</p>
<p>mfg.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082547</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082547</guid><dc:creator><![CDATA[joomoo]]></dc:creator><pubDate>Wed, 21 Jun 2006 21:31:45 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Thu, 22 Jun 2006 09:12:02 GMT]]></title><description><![CDATA[<p>Hab vor ein paar Tagen einen einfachen Laufzeittest mit array vs. vector gemacht (eben wegen Bilddaten).<br />
Probiert das mal bitte aus und sagt mir, welcher Zeitunterschied bei euch rauskommt. Bei mir war das Array um den Faktor 30(!) schneller.<br />
Deswegen hab ich mich erstmal für das Array entschieden.<br />
Aber vielleicht hab ich ja auch falsch gemessen...</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;windows.h&gt;

using namespace std;

void arr(int size)
{
	int* myArray = new int[size];

	for(int i=0; i&lt;size; i++)
		myArray[i] = 1;

	for(int j=0; j&lt;size; j++)
		myArray[j] *= 3;

	delete[] myArray;
}

void vec(int size)
{
	vector&lt;int&gt;* myVector = new vector&lt;int&gt;;

	for(int i=0; i&lt;size; i++)
		myVector-&gt;push_back(i);

	for(int j=0; j&lt;size; j++)
		(*myVector)[j] *= 3;

	delete myVector;
}

void wait()
{
	cin.clear();
	cin.ignore(cin.rdbuf()-&gt;in_avail());
	cin.get();
}

int main(void)
{
	double start = 0, end = 0;
	double arrayZeiten[10];
	double vectorZeiten[10];

	for(int i=0; i&lt;10; i++)
	{
		start = GetTickCount();
		arr(300000);
		end = GetTickCount();

		arrayZeiten[i] = end - start;

		start = GetTickCount();
		vec(300000);
		end = GetTickCount();

		vectorZeiten[i] = end - start;
	}

	double arrayD = 0, vectorD = 0;

	for(i=0; i&lt;10; i++)
		arrayD += arrayZeiten[i];

	cout &lt;&lt; &quot;Array-Zeiten: &quot; &lt;&lt; arrayD / 10 &lt;&lt; endl;	

	for(i=0; i&lt;10; i++)
		vectorD += vectorZeiten[i];

	cout &lt;&lt; &quot;Vector-Zeiten: &quot; &lt;&lt; vectorD / 10 &lt;&lt; endl;

	wait();

	return 0;
}
</code></pre>
<p>Würd mich mal interessieren, was bei euch für Werte rauskommen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082759</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082759</guid><dc:creator><![CDATA[DarthZiu]]></dc:creator><pubDate>Thu, 22 Jun 2006 09:12:02 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Thu, 22 Jun 2006 09:15:26 GMT]]></title><description><![CDATA[<p>Du machst mir Spaß, das Array initalisierst du gleich mit der richtigen Größe und den std::vector nicht, schon klar dass der langsamer ist, der muss ja ständig neuen Speicher herscheffeln. Gib dem vector die Größe gleich im Ctor mit.<br />
Im Übrigen ist es nicht notwendig, den vector selber auf dem Heap anzulegen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082763</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082763</guid><dc:creator><![CDATA[GPC]]></dc:creator><pubDate>Thu, 22 Jun 2006 09:15:26 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Thu, 22 Jun 2006 09:23:56 GMT]]></title><description><![CDATA[<p>DarthZiu schrieb:</p>
<blockquote>
<p>for(int i=0; i&lt;size; i++)<br />
myArray[i] = 1;</p>
<p>for(int i=0; i&lt;size; i++)<br />
myVector-&gt;push_back(i);</p>
</blockquote>
<p>Ist aber nicht wirklich das gleiche und push_back wird immer langsamer sein als [i].</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082772</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082772</guid><dc:creator><![CDATA[Bitte geben Sie einen Ben]]></dc:creator><pubDate>Thu, 22 Jun 2006 09:23:56 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Thu, 22 Jun 2006 09:30:21 GMT]]></title><description><![CDATA[<p>DarthZiu! Du vergleichst einen statischen &quot;Container&quot; mit einem dynamischen Container. Ehm, das passt doch irgendwie nicht. Denn das Array kann in der Form einfach nicht das leisten, was vector leisten kann. Wenn dann müsstest du mit Array die gleich Funktionalität nachbilden: bei jeder Index-Erhöhung das selbst Array resizen. Mal schauen wie schnell du dann bist.</p>
<p>Der Vector spielt dann seinen Vorteil aus, wenn dir beim Anlegen des Containers die Endgröße unbekannt ist. Da kannst du noch soviele Performancetests machen, da wird jeder vector (wenn er vernünftig implementiert ist) sehr gute Arbeit leisten.</p>
<p>Ansonst kann man auch mit reserve()-Methode nach der Vector-Konstruktion die Laufzeit für das push_back drastisch runter drücken. Dann reserviert der Vector schon mal Speicher vor und du kannst trotzdem mit push_back arbeiten, weil die size() dann unabhängig vom reserve() arbeitet. Bei GPC-Vorschlag wäre size() allerdings gleich zu Anfang &gt;0. Dann würde man anstatt push_back() den []-Op oder at() benutzen (wobei at() sicherer gg. Bufferoverflows ist, aber etwas langsamer, ggü. dem unsicheren []-Op).</p>
<p>Man muß einfach nur wissen, wie man vector benutzt, dann arbeitet dieser optimal und sicherer als jedes rohe Array.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082777</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082777</guid><dc:creator><![CDATA[Artchi]]></dc:creator><pubDate>Thu, 22 Jun 2006 09:30:21 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Thu, 22 Jun 2006 09:31:54 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">void vec(int size)
{
	vector&lt;int&gt;* myVector = new vector&lt;int&gt;(size);

	for(int i=0; i&lt;size; i++)
		(*myVector)[i] = i;

	for(int j=0; j&lt;size; j++)
		(*myVector)[j] *= 3;

	delete myVector;
}
</code></pre>
<p>Ist das jetzt richtig (effektiv)? Immer noch Faktor 10 langsamer als das Array.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082779</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082779</guid><dc:creator><![CDATA[DarthZiu]]></dc:creator><pubDate>Thu, 22 Jun 2006 09:31:54 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Thu, 22 Jun 2006 10:34:47 GMT]]></title><description><![CDATA[<p>Artchi schrieb:</p>
<blockquote>
<p>Man muß einfach nur wissen, wie man vector benutzt, dann arbeitet dieser optimal und sicherer als jedes rohe Array.</p>
</blockquote>
<p>Dass ein vector sicherer und komfortabler als ein array ist, ist mir klar. Ich benutze vectoren auch so oft wie möglich.<br />
Mein Problem ist aber, dass ich eine ziemliche Datenmenge (bis zu 20 Bilder pro Sekunde - in einer Auflösung von mindestens 640x480 (307200 Byte-Werte)) erfassen und verarbeiten muss.<br />
Hier wollte ich ebenfalls vector benutzen und habe deswegen diesen &quot;Performance-Test&quot; gemacht. Aber einen Zeitaufwand, der 5 bis 10 mal höher ist, kann ich mir an dieser Stelle einfach nicht leisten.<br />
Das ist der Grund meines ersten Posts.</p>
<p>PS: Vielleicht drücken wir den Zeitaufwand mit weiteren Verbesserungsvorschlägen ja noch auf einen annehmbaren Wert. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082802</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082802</guid><dc:creator><![CDATA[DarthZiu]]></dc:creator><pubDate>Thu, 22 Jun 2006 10:34:47 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Thu, 22 Jun 2006 11:03:38 GMT]]></title><description><![CDATA[<p>Schon mal versucht das std::vector-Objekt auf dem Stack statt auf dem Heap anzulegen? Dadurch, daß du über einen Zeiger auf dein Objekt zugreifst, hast du eine zusätzliche Indirektion, die Zeit kostet. Kann allerdings auch sein, daß das wegoptimiert wird (dazu wäre es interessant zu wissen mit welchen Optimierungs-Optionen du kompilierst).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082815</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082815</guid><dc:creator><![CDATA[Z2]]></dc:creator><pubDate>Thu, 22 Jun 2006 11:03:38 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Thu, 22 Jun 2006 11:36:24 GMT]]></title><description><![CDATA[<p>So, hier mal mein Test:</p>
<p>Ich habe deinen ersten Code so übernommen. Habe die Größe des Übergabe-Params von 300.000 auf 10.000.000 erhöht, weil bei deinen Werten mein Compilat nur 2x so langsam war und nicht 30x. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> Mit den 10.000.000x10 Durchläufen hat sich das auf 4x verlangsamt.</p>
<p>Zeit: 4 Sekunden für den Vector und 1 Sekunden für das Array.<br />
So, das war jetzt OHNE Reservierung!!!</p>
<p>Compiler: VC++ Toolkit 2003 Professional, Compiler-Optionen: cl.exe /EHsc /G7 /O2 /Og</p>
<p>Vielleicht ist einfach dein Compiler und deine Std-Lib schlecht. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /> 30x ist völlig utopisch bei 300.000 Elementen!</p>
<p>So, meine Änderung am Code:<br />
Ich habe einfach mal 10.000.000 Elemente im Vector reserviert, Push_back() verwendet und den Vector nicht mit new angelegt sondern auf dem Stack.</p>
<p>Ergebnis: sowohl Array als auch Vector brauchen 1 Sekunde!!!!!!!</p>
<p>EDIT: hier noch mal der geänderte Code:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt; 
#include &lt;vector&gt;
#include &lt;ctime&gt;

using namespace std; 

void arr(int size) 
{ 
    int* myArray = new int[size]; 

    for(int i=0; i&lt;size; i++) 
        myArray[i] = 1; 

    for(int j=0; j&lt;size; j++) 
        myArray[j] *= 3; 

    delete[] myArray; 
} 

void vec(int size) 
{ 
    vector&lt;int&gt; myVector;
	myVector.reserve(size);

    for(int i=0; i&lt;size; i++) 
        myVector.push_back(i);

    for(int j=0; j&lt;size; j++) 
        myVector[j] *= 3; 
} 

void wait() 
{ 
    cin.clear(); 
    cin.ignore(cin.rdbuf()-&gt;in_avail()); 
    cin.get(); 
} 

int main(void) 
{ 

	time_t t = time(NULL);
    for(int i=0; i&lt;10; i++) 
    { 
        arr(10000000); 
	}
    cout &lt;&lt; &quot;Array duration: &quot; &lt;&lt; (time(NULL) - t) &lt;&lt; endl;

    t = time(NULL);
	for(int i=0; i&lt;10; i++) 
	{
        vec(10000000);
    }
	cout &lt;&lt; &quot;Vector duration: &quot; &lt;&lt; (time(NULL) - t) &lt;&lt; endl;

    wait(); 

    return 0; 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1082822</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082822</guid><dc:creator><![CDATA[Artchi]]></dc:creator><pubDate>Thu, 22 Jun 2006 11:36:24 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Thu, 22 Jun 2006 11:26:27 GMT]]></title><description><![CDATA[<p>Artchi schrieb:</p>
<blockquote>
<p>Ergebnis: sowohl Array als auch Vector brauchen 1 Sekunde!!!!!!!</p>
</blockquote>
<p>klar, es nimmt sich nicht viel. am interessantesten ist ja, dass man die richtige datenstruktur waehlt, die hier eben array ist... wie man dieses array jetzt implementiert ist bei der hoch optimierten standard library von c++ ja schon fast egal.</p>
<p>es ist aber gut zu wissen dass vector immer new aufruft. den speicher also dynamisch allokiert. denn wenn man mal ganz viele kleine vectoren hat, dann _kann_ es mal ins gewicht fallen. wenn wir aber von 1 vector reden, dann ist das einfach nur egal...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082840</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082840</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Thu, 22 Jun 2006 11:26:27 GMT</pubDate></item><item><title><![CDATA[Reply to Array oder std::vector? on Thu, 22 Jun 2006 11:37:13 GMT]]></title><description><![CDATA[<p>push_back() schaut doch immer nach, ob die Größe ausreicht, er kann ja nicht wissen, dass sie reichen muss. Dann muss es doch etwas langsamer sein, als der [] Zugriff, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082848</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082848</guid><dc:creator><![CDATA[FrageBehauptung]]></dc:creator><pubDate>Thu, 22 Jun 2006 11:37:13 GMT</pubDate></item></channel></rss>