<?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[Maximale Arraygröße?]]></title><description><![CDATA[<p>Ich habe folgende Code geschrieben:</p>
<pre><code class="language-cpp">#ifndef FACTORIALDATA_H_
#define FACTORIALDATA_H_

#include &lt;string&gt;

class FactorialData {

	public:
	static const int factorialStepSize = 20000;
	double factorials[100000];
	FactorialData();
	double str2double(const std::string &amp;str);

};

#endif /* FACTORIALDATA_H_ */
</code></pre>
<p>Und die CPP-Datei</p>
<pre><code class="language-cpp">#include &quot;FactorialData.h&quot;

#include &lt;fstream&gt;
#include &lt;sstream&gt;
#include &lt;iostream&gt;

using namespace std;

FactorialData::FactorialData() {

	string line;
	ifstream file;
	file.open(&quot;factorials2&quot;);
	int index = 0;
	if( file.is_open() ) {
		while( !file.eof() ) {
			getline( file, line );
			double num = str2double( line );
			cout &lt;&lt; &quot;index = &quot; &lt;&lt; index &lt;&lt; endl;
			factorials[index] = num;
			index++;
		}
	} else
		cout &lt;&lt; &quot;Fehler beim Öffnen der Datei factorials2.&quot; &lt;&lt; endl;

	file.close();

	cout  &lt;&lt; &quot;factorials fertig.&quot; &lt;&lt; endl;
}

double FactorialData::str2double(const string &amp;str) {
	stringstream ss(str);
	double num = -1;
	if((ss &gt;&gt; num).fail())
		cout &lt;&lt; &quot;Error parsing &quot; &lt;&lt; str &lt;&lt; &quot; to double &quot; &lt;&lt; endl;
	return num;
}
</code></pre>
<p>Wenn ich das Programm ausführe erhalte ich folgenden Fehler (gdb):</p>
<blockquote>
<p>index = 22950<br />
index = 22951<br />
index = 22952<br />
index = 22953</p>
<p>Program received signal EXC_BAD_ACCESS, Could not access memory.<br />
Reason: KERN_INVALID_ADDRESS at address: 0x00048000<br />
0x00008cd8 in FactorialData::FactorialData (this=0x1b2b4) at FactorialData.cpp:20<br />
20 factorials[index] = num;</p>
</blockquote>
<p>Kann es sein, dass mein double Array zu groß gewählt ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/268097/maximale-arraygröße</link><generator>RSS for Node</generator><lastBuildDate>Wed, 02 Sep 2026 03:07:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/268097.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 04 Jun 2010 08:53:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Maximale Arraygröße? on Fri, 04 Jun 2010 08:53:26 GMT]]></title><description><![CDATA[<p>Ich habe folgende Code geschrieben:</p>
<pre><code class="language-cpp">#ifndef FACTORIALDATA_H_
#define FACTORIALDATA_H_

#include &lt;string&gt;

class FactorialData {

	public:
	static const int factorialStepSize = 20000;
	double factorials[100000];
	FactorialData();
	double str2double(const std::string &amp;str);

};

#endif /* FACTORIALDATA_H_ */
</code></pre>
<p>Und die CPP-Datei</p>
<pre><code class="language-cpp">#include &quot;FactorialData.h&quot;

#include &lt;fstream&gt;
#include &lt;sstream&gt;
#include &lt;iostream&gt;

using namespace std;

FactorialData::FactorialData() {

	string line;
	ifstream file;
	file.open(&quot;factorials2&quot;);
	int index = 0;
	if( file.is_open() ) {
		while( !file.eof() ) {
			getline( file, line );
			double num = str2double( line );
			cout &lt;&lt; &quot;index = &quot; &lt;&lt; index &lt;&lt; endl;
			factorials[index] = num;
			index++;
		}
	} else
		cout &lt;&lt; &quot;Fehler beim Öffnen der Datei factorials2.&quot; &lt;&lt; endl;

	file.close();

	cout  &lt;&lt; &quot;factorials fertig.&quot; &lt;&lt; endl;
}

double FactorialData::str2double(const string &amp;str) {
	stringstream ss(str);
	double num = -1;
	if((ss &gt;&gt; num).fail())
		cout &lt;&lt; &quot;Error parsing &quot; &lt;&lt; str &lt;&lt; &quot; to double &quot; &lt;&lt; endl;
	return num;
}
</code></pre>
<p>Wenn ich das Programm ausführe erhalte ich folgenden Fehler (gdb):</p>
<blockquote>
<p>index = 22950<br />
index = 22951<br />
index = 22952<br />
index = 22953</p>
<p>Program received signal EXC_BAD_ACCESS, Could not access memory.<br />
Reason: KERN_INVALID_ADDRESS at address: 0x00048000<br />
0x00008cd8 in FactorialData::FactorialData (this=0x1b2b4) at FactorialData.cpp:20<br />
20 factorials[index] = num;</p>
</blockquote>
<p>Kann es sein, dass mein double Array zu groß gewählt ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1906638</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1906638</guid><dc:creator><![CDATA[HändyÄndy]]></dc:creator><pubDate>Fri, 04 Jun 2010 08:53:26 GMT</pubDate></item><item><title><![CDATA[Reply to Maximale Arraygröße? on Fri, 04 Jun 2010 08:58:10 GMT]]></title><description><![CDATA[<p>Ja, ist zu groß. Das muss schließlich in den Stack passen! Wenn ich mich recht erinner ist die maximale Größe für ein Array 64 kByte. Solch große Datenmengen solltest du auf dem Heap reservieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1906643</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1906643</guid><dc:creator><![CDATA[Janjan]]></dc:creator><pubDate>Fri, 04 Jun 2010 08:58:10 GMT</pubDate></item><item><title><![CDATA[Reply to Maximale Arraygröße? on Fri, 04 Jun 2010 08:58:29 GMT]]></title><description><![CDATA[<p>Hab jetzt den Code ein wenig geändert:</p>
<pre><code class="language-cpp">class FactorialData {

	public:
	static const int factorialStepSize = 20000;
	static const int size = 100000;
	double* factorials;
	FactorialData();
	double str2double(const std::string &amp;str);

};
</code></pre>
<p>und die cpp-Datei</p>
<pre><code class="language-cpp">FactorialData::FactorialData() {

	factorials = new double[size];

	string line;
	ifstream file;
	file.open(&quot;factorials2&quot;);
	int index = 0;
//...etc...
</code></pre>
<p>Nun funktionierts.</p>
<p>Google hat mir irgendwas von Stack und Heap erzählt. Ist das der Grund? Kann mir das jemand erklären?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1906644</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1906644</guid><dc:creator><![CDATA[HändyÄndy]]></dc:creator><pubDate>Fri, 04 Jun 2010 08:58:29 GMT</pubDate></item><item><title><![CDATA[Reply to Maximale Arraygröße? on Fri, 04 Jun 2010 09:00:54 GMT]]></title><description><![CDATA[<p>HändyÄndy schrieb:</p>
<blockquote>
<p>Google hat mir irgendwas von Stack und Heap erzählt. Ist das der Grund? Kann mir das jemand erklären?</p>
</blockquote>
<p>Jedes Programm bekommt ein paar MB Stack zugewiesen bei Programmstart. In diesem Stack werden alle lokalen Variablen gespeichert. Der Client kümmert sich um den Stack, die Größe ist festgesetzt. Ist der Stack voll, crasht das Programm (Stack Overflow). Der &quot;Heap&quot; ist der restliche Arbeitsspeicher - um den kümmert das Betriebssystem sich. Dort musst du also Speicher erst beantragen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1906646</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1906646</guid><dc:creator><![CDATA[Janjan]]></dc:creator><pubDate>Fri, 04 Jun 2010 09:00:54 GMT</pubDate></item><item><title><![CDATA[Reply to Maximale Arraygröße? on Fri, 04 Jun 2010 09:03:21 GMT]]></title><description><![CDATA[<p>Und auch wieder freigeben am Ende. Macht keinen Unterschied wenn das Programm sich eh beendet, sollte man sich aber auf jeden Fall angewöhnen. In deinem Fall mit delete[] factorials;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1906647</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1906647</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Fri, 04 Jun 2010 09:03:21 GMT</pubDate></item><item><title><![CDATA[Reply to Maximale Arraygröße? on Fri, 04 Jun 2010 09:03:25 GMT]]></title><description><![CDATA[<p>Warum hast du es nicht mal mit was kleineren Ausgetestet? Wenns dann geht ist es klar die größe. Aber rein rechnerisch merkt man auch, das es das sein kann.</p>
<p>Du reservierst ein double array mit 100000 plätzen.<br />
(100.000 * 8 Byte)/1024 = 781,25 MB<br />
sollte aber eigentlich noch machbar sein. Probier mal mit kleineren Datenmengen aus und erhöhe immer etwas. Du hast ja schon nen konkreten wert ab wann das auftritt. Reservier also erstmal nur für 10.000 Elemente speicher und schau ob es damit klappt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1906648</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1906648</guid><dc:creator><![CDATA[Fedaykin]]></dc:creator><pubDate>Fri, 04 Jun 2010 09:03:25 GMT</pubDate></item><item><title><![CDATA[Reply to Maximale Arraygröße? on Fri, 04 Jun 2010 09:10:43 GMT]]></title><description><![CDATA[<p>Habe mal gelesen, dass die Stackgröße vom Compiler bestimmt wird. Darf man dem Glauben schenken? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1906652</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1906652</guid><dc:creator><![CDATA[fufufu]]></dc:creator><pubDate>Fri, 04 Jun 2010 09:10:43 GMT</pubDate></item><item><title><![CDATA[Reply to Maximale Arraygröße? on Fri, 04 Jun 2010 09:11:48 GMT]]></title><description><![CDATA[<p>fufufu schrieb:</p>
<blockquote>
<p>Habe mal gelesen, dass die Stackgröße vom Compiler bestimmt wird. Darf man dem Glauben schenken? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
</blockquote>
<p>Ja. Die kann man mit Compiler-Optionen verändern. Aber 800mb Stack machen keinen Sinn..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1906653</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1906653</guid><dc:creator><![CDATA[Janjan]]></dc:creator><pubDate>Fri, 04 Jun 2010 09:11:48 GMT</pubDate></item><item><title><![CDATA[Reply to Maximale Arraygröße? on Fri, 04 Jun 2010 09:12:42 GMT]]></title><description><![CDATA[<p>... oder benutz gleich std::vector. (und dort reserve() benutzen um unnötiges Kopieren zu verhindern, so die Größe ca. bekannt ist)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1906654</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1906654</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Fri, 04 Jun 2010 09:12:42 GMT</pubDate></item><item><title><![CDATA[Reply to Maximale Arraygröße? on Fri, 04 Jun 2010 12:09:37 GMT]]></title><description><![CDATA[<p>Fedaykin schrieb:</p>
<blockquote>
<p>Warum hast du es nicht mal mit was kleineren Ausgetestet? Wenns dann geht ist es klar die größe. Aber rein rechnerisch merkt man auch, das es das sein kann.</p>
<p>Du reservierst ein double array mit 100000 plätzen.<br />
(100.000 * 8 Byte)/1024 = 781,25 MB<br />
sollte aber eigentlich noch machbar sein. Probier mal mit kleineren Datenmengen aus und erhöhe immer etwas. Du hast ja schon nen konkreten wert ab wann das auftritt. Reservier also erstmal nur für 10.000 Elemente speicher und schau ob es damit klappt.</p>
</blockquote>
<p>Tausch mal das M gegen ein K...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1906728</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1906728</guid><dc:creator><![CDATA[ohoh]]></dc:creator><pubDate>Fri, 04 Jun 2010 12:09:37 GMT</pubDate></item><item><title><![CDATA[Reply to Maximale Arraygröße? on Fri, 04 Jun 2010 15:56:27 GMT]]></title><description><![CDATA[<p>Janjan schrieb:</p>
<blockquote>
<p>fufufu schrieb:</p>
<blockquote>
<p>Habe mal gelesen, dass die Stackgröße vom Compiler bestimmt wird. Darf man dem Glauben schenken? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
</blockquote>
<p>Ja. Die kann man mit Compiler-Optionen verändern. Aber 800mb Stack machen keinen Sinn..</p>
</blockquote>
<p>Bei rekursiven Sortierverfahren z.B. muss man für große Arrays tatsächlich den Stack vergrößern (zumindest beim GCC). Beim GCC geht das so:</p>
<pre><code>-Wl,--stack=Deine_Stack_Größe_in_Bytes
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1906842</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1906842</guid><dc:creator><![CDATA[wxSkip]]></dc:creator><pubDate>Fri, 04 Jun 2010 15:56:27 GMT</pubDate></item></channel></rss>