<?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[Speicherleck (valgrind) und class geoPoint&amp;amp; operator*( ... )]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich habe bisher diese Routine um eine Skalar-Vektor-Multiplikation auszuführen, welche mir von Valgrind(Memory Leak Toolset) als ein Speicherleck angezeigt wird und eigentlich auch zurecht, aber wie sie umzuformulieren ist, wüßte ich jetzt nicht.</p>
<pre><code class="language-cpp">class geoVector&amp; operator*(const double &amp;lhs, const class geoPoint &amp;rhs)
{
	class geoVector *tmp = new class geoVector[1]; // hier ist das Leck, aber wie
	double dValue[3] = { 0., 0., 0. }; // greife ich auf class geoVector&amp; im Funktions-Rumpf zu ?
	const double *coord = rhs.getData();

	dValue[0]=lhs*coord[0];
	dValue[1]=lhs*coord[1];
	dValue[2]=lhs*coord[2];

	tmp-&gt;setSpecial(*dValue);
	return *tmp;
}
</code></pre>
<p>Danke schonmal für durchlesen...</p>
<p>Winn</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/197004/speicherleck-valgrind-und-class-geopoint-amp-operator</link><generator>RSS for Node</generator><lastBuildDate>Wed, 30 Sep 2026 18:59:44 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/197004.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 05 Nov 2007 14:57:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Speicherleck (valgrind) und class geoPoint&amp;amp; operator*( ... ) on Mon, 05 Nov 2007 14:57:18 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich habe bisher diese Routine um eine Skalar-Vektor-Multiplikation auszuführen, welche mir von Valgrind(Memory Leak Toolset) als ein Speicherleck angezeigt wird und eigentlich auch zurecht, aber wie sie umzuformulieren ist, wüßte ich jetzt nicht.</p>
<pre><code class="language-cpp">class geoVector&amp; operator*(const double &amp;lhs, const class geoPoint &amp;rhs)
{
	class geoVector *tmp = new class geoVector[1]; // hier ist das Leck, aber wie
	double dValue[3] = { 0., 0., 0. }; // greife ich auf class geoVector&amp; im Funktions-Rumpf zu ?
	const double *coord = rhs.getData();

	dValue[0]=lhs*coord[0];
	dValue[1]=lhs*coord[1];
	dValue[2]=lhs*coord[2];

	tmp-&gt;setSpecial(*dValue);
	return *tmp;
}
</code></pre>
<p>Danke schonmal für durchlesen...</p>
<p>Winn</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1398097</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1398097</guid><dc:creator><![CDATA[Winn]]></dc:creator><pubDate>Mon, 05 Nov 2007 14:57:18 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleck (valgrind) und class geoPoint&amp;amp; operator*( ... ) on Mon, 05 Nov 2007 15:00:51 GMT]]></title><description><![CDATA[<p>Was spricht denn dagegen, eine einfache Variable zu verwenden?</p>
<pre><code class="language-cpp">geoVector operator*(const double &amp;lhs, const class geoPoint &amp;rhs)//bitte hier keine Referenz zurückgeben
{
    geoVector tmp
    double dValue[3] = { 0., 0., 0. };
    ...
    tmp.setSpecial(*dValue);
    return tmp;
}
</code></pre>
<p>(btw, Referenzen sind zwar schön und gut, aber kein Allheilmittel - in diesem Fall ist es wohl einfacher, eine Kopie zurückzugeben)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1398098</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1398098</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 05 Nov 2007 15:00:51 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleck (valgrind) und class geoPoint&amp;amp; operator*( ... ) on Mon, 05 Nov 2007 15:10:53 GMT]]></title><description><![CDATA[<p>CStoll schrieb:</p>
<blockquote>
<p>Was spricht denn dagegen, eine einfache Variable zu verwenden? (btw, Referenzen sind zwar schön und gut, aber kein Allheilmittel - in diesem Fall ist es wohl einfacher, eine Kopie zurückzugeben)</p>
</blockquote>
<p>An sich spricht da überhaupt nichts gegen, bleibt denn &quot;geoVector tmp&quot; nach Ende der geschweiften Klammer &quot;}&quot; am Leben oder wird es wegen statischer Speicher-Allokation vernichtet ? Ich probiere das mal eben aus...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1398107</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1398107</guid><dc:creator><![CDATA[Winn]]></dc:creator><pubDate>Mon, 05 Nov 2007 15:10:53 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleck (valgrind) und class geoPoint&amp;amp; operator*( ... ) on Mon, 05 Nov 2007 15:14:32 GMT]]></title><description><![CDATA[<p>Die bleibt natürlich nicht am Leben, weil sie nur lokal definiert wird. Nach der {-Klammer ist sie Geschichte. Sie braucht aber auch nicht am Leben bleiben, weil eine Kopie von tmp zurückgegeben wird.<br />
rya.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1398110</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1398110</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Mon, 05 Nov 2007 15:14:32 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleck (valgrind) und class geoPoint&amp;amp; operator*( ... ) on Mon, 05 Nov 2007 15:14:48 GMT]]></title><description><![CDATA[<p>es wird vernichtet, daher gibst du ja die kopie als variable zurück</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1398111</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1398111</guid><dc:creator><![CDATA[crashterpiece]]></dc:creator><pubDate>Mon, 05 Nov 2007 15:14:48 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleck (valgrind) und class geoPoint&amp;amp; operator*( ... ) on Mon, 05 Nov 2007 15:16:35 GMT]]></title><description><![CDATA[<p>Die lokale Variable bleibt natürlich nicht am Leben, wenn die Funktion beendet wird - aber mit der return-Anweisung wird eine Kopie dieser Variable angelegt, die das Funktionsende überlebt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1398113</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1398113</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 05 Nov 2007 15:16:35 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleck (valgrind) und class geoPoint&amp;amp; operator*( ... ) on Mon, 05 Nov 2007 15:25:02 GMT]]></title><description><![CDATA[<p>CStoll schrieb:</p>
<blockquote>
<p>Die lokale Variable bleibt natürlich nicht am Leben, wenn die Funktion beendet wird - aber mit der return-Anweisung wird eine Kopie dieser Variable angelegt, die das Funktionsende überlebt.</p>
</blockquote>
<p>Das wußte ich nicht, d.h. durch jede &quot;return object&quot; Anweisung wird eine Kopie von &quot;object&quot; erstellt. Wie detailliert ist diese Kopie ? Wird nur die Adresse kopiert oder auch alles was dahinter hängt ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1398120</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1398120</guid><dc:creator><![CDATA[Winn]]></dc:creator><pubDate>Mon, 05 Nov 2007 15:25:02 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleck (valgrind) und class geoPoint&amp;amp; operator*( ... ) on Mon, 05 Nov 2007 15:30:01 GMT]]></title><description><![CDATA[<p>Die Kopie ist so vollständig, wie es die Klasse erfordert - d.h. hierfür wird der Copy-Ctor deiner Klasse verwendet.<br />
(obwohl es noch Möglichkeiten für den Compiler gibt, das zu optimieren - siehe &quot;(n)rvo&quot;)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1398124</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1398124</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 05 Nov 2007 15:30:01 GMT</pubDate></item><item><title><![CDATA[Reply to Speicherleck (valgrind) und class geoPoint&amp;amp; operator*( ... ) on Mon, 05 Nov 2007 16:27:59 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">class geoVector *tmp = new class geoVector[1];
</code></pre>
<p>Ich hoffe, du benutzt dann auch delete[] ? Andernfalls hätte valgrind völlig recht. Unabhängig davon ist der Rest der Diskussion absolut beachtenswert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1398171</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1398171</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 05 Nov 2007 16:27:59 GMT</pubDate></item></channel></rss>