<?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[große lokale Variablen in Funktionen + globale Variablen = SEGMENTATION FAULT ?]]></title><description><![CDATA[<p>Hi,</p>
<p>ist das normal, dass Segmentation Faults entstehen, wenn die lokalen Variablen einer Funktion zuviel Speicher einnehmen? In einem anderen Programm konnte ich sogar im Debugger beobachten, dass dadurch Konstanten (!!) verändert wurden.</p>
<p>Ich habe in letzter Zeit schon ein wenig in Assembler programmiert und weiss daher, dass lokale Variablen einer Funktion (unter Linux) auf dem Stack landen... Daher glaube ich, dass der Stack evtl. zu weit nach oben wächst und dann irgendwas überschreibt... aber sollte dem Compiler sowas nicht auffallen? Immerhin ist die lokale arr-Variable von fester Größe.</p>
<p>ich habe folgendes Testprogramm gebastelt, um das Problem zu veranschaulichen:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cassert&gt;

using namespace std;

double c1 = 1;
double c2 = 2;
double c3 = 3;
double c4 = 4;
double c5 = 5;
double c6 = 6;
double c7 = 7;
double c8 = 8;
double c9 = 9;
double c10 = 10;

void test()
{
	double arr[300][300][300];

        // Segmenatation Fault ?!... aber nur wenn Variable arr zuviel Speicher belegt :D
	cout &lt;&lt; c1 &lt;&lt; &quot;, &quot; &lt;&lt; c2 &lt;&lt; &quot;, &quot; &lt;&lt; c3 &lt;&lt; &quot;, &quot; &lt;&lt; c4 
	&lt;&lt; &quot;, &quot; &lt;&lt; c5 &lt;&lt; &quot;, &quot; &lt;&lt; c6 &lt;&lt; &quot;, &quot; &lt;&lt; c7 &lt;&lt; &quot;, &quot; &lt;&lt; c8 
	&lt;&lt; &quot;, &quot; &lt;&lt; c9 &lt;&lt; &quot;, &quot; &lt;&lt; c10 &lt;&lt; endl;

	assert(c1 == 1);
	assert(c2 == 2);
	assert(c3 == 3);
	assert(c4 == 4);
	assert(c5 == 5);
	assert(c6 == 6);
	assert(c7 == 7);
	assert(c8 == 8);
	assert(c9 == 9);
	assert(c10 == 10);
}

int main(int argc, char* argv[])
{
	test();
}
</code></pre>
<p>Ist der einzige Ausweg in diesem Fall wirklich nur ein dynamisches Array?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/221792/große-lokale-variablen-in-funktionen-globale-variablen-segmentation-fault</link><generator>RSS for Node</generator><lastBuildDate>Mon, 05 Oct 2026 22:48:33 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/221792.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 03 Sep 2008 14:52:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to große lokale Variablen in Funktionen + globale Variablen = SEGMENTATION FAULT ? on Wed, 03 Sep 2008 14:53:11 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ist das normal, dass Segmentation Faults entstehen, wenn die lokalen Variablen einer Funktion zuviel Speicher einnehmen? In einem anderen Programm konnte ich sogar im Debugger beobachten, dass dadurch Konstanten (!!) verändert wurden.</p>
<p>Ich habe in letzter Zeit schon ein wenig in Assembler programmiert und weiss daher, dass lokale Variablen einer Funktion (unter Linux) auf dem Stack landen... Daher glaube ich, dass der Stack evtl. zu weit nach oben wächst und dann irgendwas überschreibt... aber sollte dem Compiler sowas nicht auffallen? Immerhin ist die lokale arr-Variable von fester Größe.</p>
<p>ich habe folgendes Testprogramm gebastelt, um das Problem zu veranschaulichen:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;cassert&gt;

using namespace std;

double c1 = 1;
double c2 = 2;
double c3 = 3;
double c4 = 4;
double c5 = 5;
double c6 = 6;
double c7 = 7;
double c8 = 8;
double c9 = 9;
double c10 = 10;

void test()
{
	double arr[300][300][300];

        // Segmenatation Fault ?!... aber nur wenn Variable arr zuviel Speicher belegt :D
	cout &lt;&lt; c1 &lt;&lt; &quot;, &quot; &lt;&lt; c2 &lt;&lt; &quot;, &quot; &lt;&lt; c3 &lt;&lt; &quot;, &quot; &lt;&lt; c4 
	&lt;&lt; &quot;, &quot; &lt;&lt; c5 &lt;&lt; &quot;, &quot; &lt;&lt; c6 &lt;&lt; &quot;, &quot; &lt;&lt; c7 &lt;&lt; &quot;, &quot; &lt;&lt; c8 
	&lt;&lt; &quot;, &quot; &lt;&lt; c9 &lt;&lt; &quot;, &quot; &lt;&lt; c10 &lt;&lt; endl;

	assert(c1 == 1);
	assert(c2 == 2);
	assert(c3 == 3);
	assert(c4 == 4);
	assert(c5 == 5);
	assert(c6 == 6);
	assert(c7 == 7);
	assert(c8 == 8);
	assert(c9 == 9);
	assert(c10 == 10);
}

int main(int argc, char* argv[])
{
	test();
}
</code></pre>
<p>Ist der einzige Ausweg in diesem Fall wirklich nur ein dynamisches Array?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1575950</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1575950</guid><dc:creator><![CDATA[moormaster]]></dc:creator><pubDate>Wed, 03 Sep 2008 14:53:11 GMT</pubDate></item><item><title><![CDATA[Reply to große lokale Variablen in Funktionen + globale Variablen = SEGMENTATION FAULT ? on Wed, 03 Sep 2008 15:50:10 GMT]]></title><description><![CDATA[<p>So ist es. Der Stack nimmt nicht beliebig viel auf, insbesondere keine 200MB, eher sowas im Kilobyte-Bereich. Für Größeres musst du den Heap benutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1576003</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1576003</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Wed, 03 Sep 2008 15:50:10 GMT</pubDate></item><item><title><![CDATA[Reply to große lokale Variablen in Funktionen + globale Variablen = SEGMENTATION FAULT ? on Wed, 03 Sep 2008 15:59:31 GMT]]></title><description><![CDATA[<p>moormaster schrieb:</p>
<blockquote>
<pre><code class="language-cpp">double arr[300][300][300];
</code></pre>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1576005</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1576005</guid><dc:creator><![CDATA[sothis_]]></dc:creator><pubDate>Wed, 03 Sep 2008 15:59:31 GMT</pubDate></item><item><title><![CDATA[Reply to große lokale Variablen in Funktionen + globale Variablen = SEGMENTATION FAULT ? on Wed, 03 Sep 2008 16:55:18 GMT]]></title><description><![CDATA[<p>Ich weiss selbst, dass das groß is <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="😃"
    /> Mich wundert es nur, dass der Compiler nix dazu sagt... der müsste doch als erster merken, dass das nich auf den Stack passt?</p>
<p>Ich habe ein großes Programm, was mal jmd. geschrieben hat, welches derart große Arrays verwendet hat... Das lief auch so auf einem Cluster mit 64 Bit.</p>
<p>Bei Wechsel der plattform auf &quot;Normalrechner&quot; machen diese großen Arrays nun Probleme und ich muss offenbar zusehen, dass der ganze Kram nun dynamisch alloziiert wird <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1576028</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1576028</guid><dc:creator><![CDATA[moormaster]]></dc:creator><pubDate>Wed, 03 Sep 2008 16:55:18 GMT</pubDate></item><item><title><![CDATA[Reply to große lokale Variablen in Funktionen + globale Variablen = SEGMENTATION FAULT ? on Wed, 03 Sep 2008 17:17:39 GMT]]></title><description><![CDATA[<p>moormaster schrieb:</p>
<blockquote>
<p>Ich habe ein großes Programm, was mal jmd. geschrieben hat, welches derart große Arrays verwendet hat...</p>
</blockquote>
<p>Ich frag jetzt nicht, wie man auf solche Ideen kommt...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1576034</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1576034</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Wed, 03 Sep 2008 17:17:39 GMT</pubDate></item><item><title><![CDATA[Reply to große lokale Variablen in Funktionen + globale Variablen = SEGMENTATION FAULT ? on Wed, 03 Sep 2008 17:26:23 GMT]]></title><description><![CDATA[<p>Auf diese Idee kommt man wohl, wenn man nur programmiert, um ein Problem zu lösen und sich nicht mit dynamischer Speicherreservierung herumplagen möchte... es war nicht meine Idee die Arrays so anzulegen <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="😃"
    /> Ich habe nur versucht mich darumzudrücken, das alles auch noch ändern zu müssen <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1576038</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1576038</guid><dc:creator><![CDATA[moormaster]]></dc:creator><pubDate>Wed, 03 Sep 2008 17:26:23 GMT</pubDate></item><item><title><![CDATA[Reply to große lokale Variablen in Funktionen + globale Variablen = SEGMENTATION FAULT ? on Thu, 04 Sep 2008 00:18:59 GMT]]></title><description><![CDATA[<p>Der Compiler sagt nix dazu weil er üblicherweise die grösse des Stacks nicht kennt. Die Stackgrösse kannst du oft beim Linken angeben. Beim MSVC z.B. (genauer Visual Studio) gibt's dazu ein hübsches Feld in den Linker-Einstellungen, da kannst du ja mal &quot;524288000&quot; (500MB) reinschreiben wenn du willst (falls du Visual Studio verwendest).<br />
Wenn das Programm nur einen einzigen Thread verwendet sollte das sogar auf normalen 32 Bit Windows Systemen laufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1576198</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1576198</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Thu, 04 Sep 2008 00:18:59 GMT</pubDate></item><item><title><![CDATA[Reply to große lokale Variablen in Funktionen + globale Variablen = SEGMENTATION FAULT ? on Thu, 04 Sep 2008 07:24:45 GMT]]></title><description><![CDATA[<p>Danke, ich werd mal die manpages vom g++ durchschauen, welcher Parameter dafür zuständig ist <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1576263</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1576263</guid><dc:creator><![CDATA[moormaster]]></dc:creator><pubDate>Thu, 04 Sep 2008 07:24:45 GMT</pubDate></item><item><title><![CDATA[Reply to große lokale Variablen in Funktionen + globale Variablen = SEGMENTATION FAULT ? on Thu, 04 Sep 2008 07:56:57 GMT]]></title><description><![CDATA[<p>Das hat nicht einmal was mit dem Programm an sich zu tun. Unter Linux zB einfach mit ulimit -s &lt;LIMIT&gt; die gewünschte Stackgröße setzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1576282</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1576282</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Thu, 04 Sep 2008 07:56:57 GMT</pubDate></item><item><title><![CDATA[Reply to große lokale Variablen in Funktionen + globale Variablen = SEGMENTATION FAULT ? on Thu, 04 Sep 2008 08:05:57 GMT]]></title><description><![CDATA[<p>Fellhuhn schrieb:</p>
<blockquote>
<p>Das hat nicht einmal was mit dem Programm an sich zu tun. Unter Linux zB einfach mit ulimit -s &lt;LIMIT&gt; die gewünschte Stackgröße setzen.</p>
</blockquote>
<p>Danke! Das hat definitiv gepasst <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="😃"
    /> Die alte Grenze des Stacks stand auf 8 MB, was in etwa zu meinen Beobachtungen passt. Stell ich das auf &gt; ~205Mb dann läuft obiges Programm ohne Fehler durch.</p>
<p>Können mir durch eine zu eine hohe Stack-Grenze irgendwelche Nachteile entstehen? Bleibt dann generell weniger Platz für dynamisch alloziierten Speicher oder erst, wenn der Stack tatsächlich so groß wird?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1576290</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1576290</guid><dc:creator><![CDATA[moormaster]]></dc:creator><pubDate>Thu, 04 Sep 2008 08:05:57 GMT</pubDate></item><item><title><![CDATA[Reply to große lokale Variablen in Funktionen + globale Variablen = SEGMENTATION FAULT ? on Thu, 04 Sep 2008 09:10:45 GMT]]></title><description><![CDATA[<p>Abgesehen davon das es &quot;schlechter Stil&quot; ist, weil man normalerweise nicht von jedem erwarten kann das er manuell seinen Stack einstellt, ist der einzige Nachteil das der dynamische Speicherbereich der dem Prozess zur Verfügung gestellt wird entsprechend kleiner wird. Also im Grunde hast du die gleiche Menge an Speicher, nur eben weniger Heap, dafür mehr Stack.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1576321</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1576321</guid><dc:creator><![CDATA[Fellhuhn]]></dc:creator><pubDate>Thu, 04 Sep 2008 09:10:45 GMT</pubDate></item><item><title><![CDATA[Reply to große lokale Variablen in Funktionen + globale Variablen = SEGMENTATION FAULT ? on Thu, 04 Sep 2008 09:28:15 GMT]]></title><description><![CDATA[<p>Ok <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/1576335</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1576335</guid><dc:creator><![CDATA[moormaster]]></dc:creator><pubDate>Thu, 04 Sep 2008 09:28:15 GMT</pubDate></item></channel></rss>