<?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[statische objekte in funktionen]]></title><description><![CDATA[<p>Hallo,<br />
Wann wird ihr Speicher freigegeben?</p>
<pre><code class="language-cpp">aObject&amp; test()
{
  static aObject Result = aObject(...);
  return Result;
}

int main()
{
  aObject X = test();
  ....

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/274868/statische-objekte-in-funktionen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 07:55:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/274868.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 04 Oct 2010 16:22:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to statische objekte in funktionen on Mon, 04 Oct 2010 16:22:14 GMT]]></title><description><![CDATA[<p>Hallo,<br />
Wann wird ihr Speicher freigegeben?</p>
<pre><code class="language-cpp">aObject&amp; test()
{
  static aObject Result = aObject(...);
  return Result;
}

int main()
{
  aObject X = test();
  ....

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1961238</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1961238</guid><dc:creator><![CDATA[statiker]]></dc:creator><pubDate>Mon, 04 Oct 2010 16:22:14 GMT</pubDate></item><item><title><![CDATA[Reply to statische objekte in funktionen on Mon, 04 Oct 2010 16:28:21 GMT]]></title><description><![CDATA[<p>Wenn das Programm beendet wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1961242</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1961242</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 04 Oct 2010 16:28:21 GMT</pubDate></item><item><title><![CDATA[Reply to statische objekte in funktionen on Mon, 04 Oct 2010 16:28:22 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>nach dem Ende von main. Dann werden auch die Destructoren aufgerufen.</p>
<p>mfg Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1961243</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1961243</guid><dc:creator><![CDATA[mgaeckler]]></dc:creator><pubDate>Mon, 04 Oct 2010 16:28:22 GMT</pubDate></item><item><title><![CDATA[Reply to statische objekte in funktionen on Mon, 04 Oct 2010 16:34:16 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Wenn das Programm beendet wird.</p>
</blockquote>
<p>bedeutet es, das dann langsam der Speicher zugemüllt wird, wenn man die Funktion oft verwendet?</p>
<pre><code class="language-cpp">for( int I=0; I &lt; 100 ; ++I )
{
  aObject X = test(...);
  X-&gt;DoSth();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1961247</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1961247</guid><dc:creator><![CDATA[statiker]]></dc:creator><pubDate>Mon, 04 Oct 2010 16:34:16 GMT</pubDate></item><item><title><![CDATA[Reply to statische objekte in funktionen on Mon, 04 Oct 2010 16:39:01 GMT]]></title><description><![CDATA[<p>static aObject Result;</p>
<p>Result wird einmal (beim ersten Aufruf von test()) konstruiert und beim Verlassen von main() zerstört.<br />
In der Schleife wird das statische Objekt jeweils einmal kopiert (nicht referenziert), diese Kopie wird jeweils beim Schleifenende zerstört.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1961252</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1961252</guid><dc:creator><![CDATA[VF]]></dc:creator><pubDate>Mon, 04 Oct 2010 16:39:01 GMT</pubDate></item><item><title><![CDATA[Reply to statische objekte in funktionen on Mon, 04 Oct 2010 17:35:11 GMT]]></title><description><![CDATA[<p>statiker schrieb:</p>
<blockquote>
<p>SeppJ schrieb:</p>
<blockquote>
<p>Wenn das Programm beendet wird.</p>
</blockquote>
<p>bedeutet es, das dann langsam der Speicher zugemüllt wird, wenn man die Funktion oft verwendet?</p>
<pre><code class="language-cpp">for( int I=0; I &lt; 100 ; ++I )
{
  aObject X = test(...);
  X-&gt;DoSth();
}
</code></pre>
</blockquote>
<p>Moment. Du hast hier zwei Objekte:</p>
<p>Einmal das statische Objekt in test() und einmal das lokale Objekt on der Forschleife. Nur das statische Objekt wird nach dem Ende von main zerstört. Das lokale Objekt wird schon am Ende der for-schleife zerstört.</p>
<p>mfg Martin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1961273</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1961273</guid><dc:creator><![CDATA[mgaeckler]]></dc:creator><pubDate>Mon, 04 Oct 2010 17:35:11 GMT</pubDate></item><item><title><![CDATA[Reply to statische objekte in funktionen on Mon, 04 Oct 2010 17:35:36 GMT]]></title><description><![CDATA[<p>statiker schrieb:</p>
<blockquote>
<p>bedeutet es, das dann langsam der Speicher zugemüllt wird, wenn man die Funktion oft verwendet?</p>
<pre><code class="language-cpp">for( int I=0; I &lt; 100 ; ++I )
{
  aObject X = test(...);
  X-&gt;DoSth();
}
</code></pre>
</blockquote>
<p>Nein. Das Objekt <code>X</code> ist lokal und wird am Ende jedes Schleifendurchgangs (beim <code>}</code> ) zerstört.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1961274</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1961274</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Mon, 04 Oct 2010 17:35:36 GMT</pubDate></item><item><title><![CDATA[Reply to statische objekte in funktionen on Tue, 05 Oct 2010 10:29:43 GMT]]></title><description><![CDATA[<p>[quote]bedeutet es, das dann langsam der Speicher zugemüllt wird, wenn man die <strong>Funktion</strong> oft verwendet?[quote]</p>
<p>Nein, das wird nicht passieren, egal wie oft du die Funktion aufrufst, die darin enthaltene Deklaration samit Initialisierung wird nur einmal durchgeführt.<br />
folgende funktion mal asl etwas intuitiveres Beispiel<br />
func()<br />
{<br />
static int i = 0;<br />
i++;<br />
}</p>
<p>rufst du func 5 mal auf, hat i den Wert 5 und nicht 1, weil static int i = 0 nur einmal durchgeführt wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1961571</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1961571</guid><dc:creator><![CDATA[Ka-Mensch]]></dc:creator><pubDate>Tue, 05 Oct 2010 10:29:43 GMT</pubDate></item></channel></rss>