<?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[Speicherleak?]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich hätte mal eine Frage bezüglich des C/C++ Standards.</p>
<p>Wenn ich mir mittels folgendem Code ein Array an chars anlege, welche ich brauche um die entsprechenden Dateien zu laden:</p>
<pre><code>char* fs[] = {&quot;shader1.frag&quot;, &quot;shader2.frag&quot;};
</code></pre>
<p>Muss ich für fs noch ein delete aufrufen? Oder ist das eine lokale Variable?</p>
<p>Ich hab über das Program mal valgrind laufen lassen, welches mir keinerlei Speicherleaks gemeldet hat.<br />
Aber rein von der Intuition her müsste doch eines entstehen, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/222648/speicherleak</link><generator>RSS for Node</generator><lastBuildDate>Sun, 04 Oct 2026 19:18:30 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/222648.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 15 Sep 2008 17:32:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Speicherleak? on Mon, 15 Sep 2008 17:32:27 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich hätte mal eine Frage bezüglich des C/C++ Standards.</p>
<p>Wenn ich mir mittels folgendem Code ein Array an chars anlege, welche ich brauche um die entsprechenden Dateien zu laden:</p>
<pre><code>char* fs[] = {&quot;shader1.frag&quot;, &quot;shader2.frag&quot;};
</code></pre>
<p>Muss ich für fs noch ein delete aufrufen? Oder ist das eine lokale Variable?</p>
<p>Ich hab über das Program mal valgrind laufen lassen, welches mir keinerlei Speicherleaks gemeldet hat.<br />
Aber rein von der Intuition her müsste doch eines entstehen, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1582368</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1582368</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Mon, 15 Sep 2008 17:32:27 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Mon, 15 Sep 2008 17:35:17 GMT]]></title><description><![CDATA[<p>Nein, wieso sollte eins entstehen? Dein Array fs wird lokal angelegt (also automatisch am Ende des Gültigkeitsbereichs entsorgt) und enthält dann zwei char Zeiger, die auf deine beiden c-string Konstanten zeigen und für die willst du doch wohl auch kein delete aufrufen, oder?</p>
<p>Felix</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1582369</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1582369</guid><dc:creator><![CDATA[Phoemuex]]></dc:creator><pubDate>Mon, 15 Sep 2008 17:35:17 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Mon, 15 Sep 2008 17:35:34 GMT]]></title><description><![CDATA[<p>nur was du mit new erstellt hast musst du auch mit delete löschen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1582370</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1582370</guid><dc:creator><![CDATA[JustAnotherNoob]]></dc:creator><pubDate>Mon, 15 Sep 2008 17:35:34 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Mon, 15 Sep 2008 17:36:06 GMT]]></title><description><![CDATA[<p>Jiddoo schrieb:</p>
<blockquote>
<p>[...] Aber rein von der Intuition her müsste doch eines entstehen, oder?</p>
</blockquote>
<p>Wieso denn das?</p>
<p><code>fs</code> ist ein Array aus <code>char *</code> . Die Elemente des Arrays zeigen auf Zeichenkettenliterale.</p>
<p>cheers, Swordfish</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1582372</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1582372</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Mon, 15 Sep 2008 17:36:06 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Mon, 15 Sep 2008 17:36:36 GMT]]></title><description><![CDATA[<p>Jiddoo schrieb:</p>
<blockquote>
<p>Muss ich für fs noch ein delete aufrufen? Oder ist das eine lokale Variable?</p>
<p>Ich hab über das Program mal valgrind laufen lassen, welches mir keinerlei Speicherleaks gemeldet hat.<br />
Aber rein von der Intuition her müsste doch eines entstehen, oder?</p>
</blockquote>
<p>Grundsätzlich:<br />
Für jedes new/new[] ein delete/delete[]. Du allozierst nichts mit new/new[] also ist auch kein deallozieren nötig.</p>
<p>Persönlich würde ich dennoch eher std::string als char* verwenden...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1582373</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1582373</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Mon, 15 Sep 2008 17:36:36 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Mon, 15 Sep 2008 17:50:06 GMT]]></title><description><![CDATA[<p>asc schrieb:</p>
<blockquote>
<p>Persönlich würde ich dennoch eher std::string als char* verwenden...</p>
</blockquote>
<p>Und wenn wir schon dabei sind, gerade <code>std::vector</code> statt Arrays. Wobei ich bei Konstanten und Literalen manchmal auch eher zu <code>const char*</code> und C-Arrays greife...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1582388</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1582388</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Mon, 15 Sep 2008 17:50:06 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Mon, 15 Sep 2008 18:05:06 GMT]]></title><description><![CDATA[<p>Da die char's wohl global sind wuerde ich hier nicht auf std::string zurueckgreifen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1582400</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1582400</guid><dc:creator><![CDATA[nenenene]]></dc:creator><pubDate>Mon, 15 Sep 2008 18:05:06 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Mon, 15 Sep 2008 18:33:06 GMT]]></title><description><![CDATA[<p>nenenene schrieb:</p>
<blockquote>
<p>Da die char's wohl global sind wuerde ich hier nicht auf std::string zurueckgreifen.</p>
</blockquote>
<p>Was hat das mit global zu tun? Eigentlich sollte man dann erst recht <code>std::string</code> verwenden, weil globale Objekte noch von viel mehr Orten beeinträchtigt werden können...</p>
<p>Oder meinst du konstant? Also als Literale?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1582422</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1582422</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Mon, 15 Sep 2008 18:33:06 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Mon, 15 Sep 2008 18:48:36 GMT]]></title><description><![CDATA[<p>Hmm das meinte ich :D. Hab das irgendwie impliziert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1582431</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1582431</guid><dc:creator><![CDATA[nenenene]]></dc:creator><pubDate>Mon, 15 Sep 2008 18:48:36 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Mon, 15 Sep 2008 19:25:40 GMT]]></title><description><![CDATA[<p>Für global: Design ändern, globale Variablen sind in viele Fällen Pfui.<br />
Für konstant: Dann halt std::vector&lt;std::string const&gt; <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_tongue"
      title=":P"
      alt="😛"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1582450</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1582450</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Mon, 15 Sep 2008 19:25:40 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Mon, 15 Sep 2008 19:45:09 GMT]]></title><description><![CDATA[<p>pumuckl schrieb:</p>
<blockquote>
<p>std::vector&lt;std::string const&gt;</p>
</blockquote>
<p>Standard 23.1.3 schrieb:</p>
<blockquote>
<p>The type of objects stored in these components must meet the requirements of CopyConstructible types (lib.copyconstructible), and the additional requirements of Assignable types.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1582471</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1582471</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Mon, 15 Sep 2008 19:45:09 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Thu, 18 Sep 2008 07:57:15 GMT]]></title><description><![CDATA[<p>Wenn</p>
<pre><code>char* fs[] = {&quot;shader1.frag&quot;, &quot;shader2.frag&quot;};
</code></pre>
<p>die Variablen global anlegt, dann ist das vielleicht kein direktes Speicherleak aber irgendwie ja trotzdem nicht das, was man gerne hätte, wenn das dann bis zum Beenden des Programms irgendwo rumschwirrt.</p>
<p>Aber das müsste doch eigentlich nur lokal gültig sein, wenn es innerhalb einer Funktion angelegt wurde, oder?</p>
<p>Ich persönlich würde auch vector und string benutzen aber dann würde aus obigem schön kurzen Code folgendes:</p>
<pre><code>std::vector&lt;std::string&gt; fs;
fs.push_back(string(&quot;shader1.frag&quot;);
fs.push_back(string(&quot;shader2.frag&quot;);
</code></pre>
<p>Was den Code irgendwie unschön aufbläht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1584033</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1584033</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Thu, 18 Sep 2008 07:57:15 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Thu, 18 Sep 2008 08:10:20 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Jiddoo schrieb:</p>
<blockquote>
<p>Wenn</p>
<pre><code>char* fs[] = {&quot;shader1.frag&quot;, &quot;shader2.frag&quot;};
</code></pre>
<p>die Variablen global anlegt, dann ist das vielleicht kein direktes Speicherleak aber irgendwie ja trotzdem nicht das, was man gerne hätte, wenn das dann bis zum Beenden des Programms irgendwo rumschwirrt.</p>
<p>Aber das müsste doch eigentlich nur lokal gültig sein, wenn es innerhalb einer Funktion angelegt wurde, oder?</p>
</blockquote>
<p>Entscheidend ist, was hier lokal definiert wurde: Ein Zeiger-Array, also wird das Array mit den Zeigern wieder abgeräumt, aber die Zeichenketten verbleiben noch in einem schreibgeschützten Speichersegment, wie jedes Zeichenkettenliteral.</p>
<p>MfG,</p>
<p>Probe-Nutzer</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1584040</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1584040</guid><dc:creator><![CDATA[Probe-Nutzer]]></dc:creator><pubDate>Thu, 18 Sep 2008 08:10:20 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Thu, 18 Sep 2008 08:16:30 GMT]]></title><description><![CDATA[<p>KasF schrieb:</p>
<blockquote>
<p>pumuckl schrieb:</p>
<blockquote>
<p>std::vector&lt;std::string const&gt;</p>
</blockquote>
<p>Standard 23.1.3 schrieb:</p>
<blockquote>
<p>The type of objects stored in these components must meet the requirements of CopyConstructible types (lib.copyconstructible), and the additional requirements of Assignable types.</p>
</blockquote>
</blockquote>
<p>Jup, natürlich. Allerdings kann man den darauf folgenden Abschnitten und den Beschreibungen der vector-Methoden auch entnehmen, dass kein op= aufgerufen wird, wenn außer Ctor und const-methoden nur push/pop_back benutzt werden. Ist eine Frage der Implementation (Compiler bzw. STL), ob solch eine &quot;bedingt standardkonforme&quot; Verwendung toleriert wird. Mir ist noch kein Compiler über den Weg gelaufen der nicht kulant genug wäre...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1584044</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1584044</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 18 Sep 2008 08:16:30 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Thu, 18 Sep 2008 09:12:40 GMT]]></title><description><![CDATA[<blockquote>
<p>Was den Code irgendwie unschön aufbläht.</p>
</blockquote>
<p>Imo ist das kein Grund das nicht so zu machen. Klar ist es ein wenig mehr Schreibarbeit, aber wenn du es so machst, dann hast du da viel mehr Klarheit, was du vor hast und was du damit gedenkst zu tun. Zum anderen kannst du da sehr viel einfacher dynamisch laden, was bei einem realistischem Programm eher der Fall sein wird, als das du das im hardcodest. Das ist mit Array's nämlich gar nicht möglich, ohne ein vector/list-ähnliches Gebilde nachzuprogrammieren.</p>
<p>Im übrigen brauchst du den Konstruktor von string nicht explizit aufzurufen. std::string hat einen nicht expliziten Konstuktor für const char* . <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/1584085</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1584085</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Thu, 18 Sep 2008 09:12:40 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Thu, 18 Sep 2008 12:20:50 GMT]]></title><description><![CDATA[<blockquote>
<p>aber die Zeichenketten verbleiben noch in einem schreibgeschützten Speichersegment, wie jedes Zeichenkettenliteral.</p>
</blockquote>
<p>Der Standard macht keine Aussage darüber wo string literals leben und ob dieser Bereich schreibgeschützt ist oder nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1584227</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1584227</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Thu, 18 Sep 2008 12:20:50 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Thu, 18 Sep 2008 13:39:44 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>hustbaer schrieb:</p>
<blockquote>
<blockquote>
<p>aber die Zeichenketten verbleiben noch in einem schreibgeschützten Speichersegment, wie jedes Zeichenkettenliteral.</p>
</blockquote>
<p>Der Standard macht keine Aussage darüber wo string literals leben und ob dieser Bereich schreibgeschützt ist oder nicht.</p>
</blockquote>
<p>Das ist klar, aber in der Praxis wird man diesen Fall oft genug finden.</p>
<p>MfG,</p>
<p>Probe-Nutzer</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1584313</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1584313</guid><dc:creator><![CDATA[Probe-Nutzer]]></dc:creator><pubDate>Thu, 18 Sep 2008 13:39:44 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Thu, 18 Sep 2008 13:43:06 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<blockquote>
<p>aber die Zeichenketten verbleiben noch in einem schreibgeschützten Speichersegment, wie jedes Zeichenkettenliteral.</p>
</blockquote>
<p>Der Standard macht keine Aussage darüber wo string literals leben und ob dieser Bereich schreibgeschützt ist oder nicht.</p>
</blockquote>
<p>Jo, und die Aussage impliziert dann auch das gute undefinierte Verhalten, wenn man auf einem Literal rumschreibt. Deshalb sollte man es besser sein lassen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1584318</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1584318</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Thu, 18 Sep 2008 13:43:06 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Thu, 18 Sep 2008 14:33:11 GMT]]></title><description><![CDATA[<p>pumuckl schrieb:</p>
<blockquote>
<p>Jup, natürlich. Allerdings kann man den darauf folgenden Abschnitten und den Beschreibungen der vector-Methoden auch entnehmen, dass kein op= aufgerufen wird, wenn außer Ctor und const-methoden nur push/pop_back benutzt werden. Ist eine Frage der Implementation (Compiler bzw. STL), ob solch eine &quot;bedingt standardkonforme&quot; Verwendung toleriert wird. Mir ist noch kein Compiler über den Weg gelaufen der nicht kulant genug wäre...</p>
</blockquote>
<p>Der Compiler(g++) steigt bei mir auch schon viel vorher, beim Allocator aus:</p>
<pre><code class="language-cpp">pointer
address(reference __x) const { return &amp;__x; }

const_pointer
address(const_reference __x) const { return &amp;__x; }
</code></pre>
<p>Da durch ein const T im Container, die zweite Funktion versucht die Erste zu redefinieren. Beim Comeau genauso.</p>
<p>Welcher Compiler, bzw welche Implementation lässt es denn zu ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1584363</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1584363</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Thu, 18 Sep 2008 14:33:11 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Thu, 18 Sep 2008 15:05:42 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>KasF schrieb:</p>
<blockquote>
<p>Welcher Compiler, bzw welche Implementation lässt es denn zu ?</p>
</blockquote>
<p>VS2005, SP1 hat nichts daran auszusetzen.</p>
<p>MfG,</p>
<p>Probe-Nutzer</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1584403</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1584403</guid><dc:creator><![CDATA[Probe-Nutzer]]></dc:creator><pubDate>Thu, 18 Sep 2008 15:05:42 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Thu, 18 Sep 2008 22:06:44 GMT]]></title><description><![CDATA[<p>Probe-Nutzer schrieb:</p>
<blockquote>
<p>VS2005, SP1 hat nichts daran auszusetzen.</p>
</blockquote>
<p>VS08 genauso, lässt sogar folgendes durchgehen:</p>
<pre><code class="language-cpp">vector&lt;const int&gt; a(2);
a[0] = 6;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1584573</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1584573</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Thu, 18 Sep 2008 22:06:44 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleak? on Thu, 18 Sep 2008 22:29:32 GMT]]></title><description><![CDATA[<p><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#274" rel="nofollow">C++ Standard Library Defect 274. a missing/impossible allocator requirement</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1584575</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1584575</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Thu, 18 Sep 2008 22:29:32 GMT</pubDate></item></channel></rss>