<?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[Return value]]></title><description><![CDATA[<p>Mein Kollege meinte es wäre nicht mehr nötig ein Objekt via Referenz zu übergeben, um es zu modifizieren. Durch <strong>Return-Value-Optimization</strong> könnte man das Objekt auch lokal anlegen und zurückgeben, ohne Performance zu verlieren.</p>
<p>Hier mal ein Beispiel:</p>
<pre><code>vector&lt;VeryBig&gt; foo() {
  vector&lt;VeryBig&gt; v;
  // fill &quot;v&quot;
  return v;
}
</code></pre>
<p>Ich ziehe bisher die klassische Implementierung vor, weil ich mich nicht darauf verlassen möchte, dass der Compiler das auch optimiert.</p>
<pre><code>void foo(vector&lt;VeryBig&gt;&amp; v) {
  // fill &quot;v&quot;
}
</code></pre>
<p>Oder kann ich beruhigt große Objekte zurückgeben?</p>
<p><strong>PS:</strong><br />
Ich kenne den Compiler nicht, da es plattformunabhängiger Code für eine Libary wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/319288/return-value</link><generator>RSS for Node</generator><lastBuildDate>Sat, 25 Jul 2026 20:13:35 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/319288.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 13 Aug 2013 11:20:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Return value on Tue, 13 Aug 2013 11:20:48 GMT]]></title><description><![CDATA[<p>Mein Kollege meinte es wäre nicht mehr nötig ein Objekt via Referenz zu übergeben, um es zu modifizieren. Durch <strong>Return-Value-Optimization</strong> könnte man das Objekt auch lokal anlegen und zurückgeben, ohne Performance zu verlieren.</p>
<p>Hier mal ein Beispiel:</p>
<pre><code>vector&lt;VeryBig&gt; foo() {
  vector&lt;VeryBig&gt; v;
  // fill &quot;v&quot;
  return v;
}
</code></pre>
<p>Ich ziehe bisher die klassische Implementierung vor, weil ich mich nicht darauf verlassen möchte, dass der Compiler das auch optimiert.</p>
<pre><code>void foo(vector&lt;VeryBig&gt;&amp; v) {
  // fill &quot;v&quot;
}
</code></pre>
<p>Oder kann ich beruhigt große Objekte zurückgeben?</p>
<p><strong>PS:</strong><br />
Ich kenne den Compiler nicht, da es plattformunabhängiger Code für eine Libary wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2345495</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2345495</guid><dc:creator><![CDATA[Tomahawk]]></dc:creator><pubDate>Tue, 13 Aug 2013 11:20:48 GMT</pubDate></item><item><title><![CDATA[Reply to Return value on Tue, 13 Aug 2013 11:23:55 GMT]]></title><description><![CDATA[<p>Dein Kollege hat absolut Recht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2345496</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2345496</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 13 Aug 2013 11:23:55 GMT</pubDate></item><item><title><![CDATA[Reply to Return value on Tue, 13 Aug 2013 11:30:41 GMT]]></title><description><![CDATA[<p>Nun, sagen wir mal: Bei aktuellen Compilern. Wenn jetzt ein g++ 3.0 genommen wird, dann wird es wohl nicht so sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2345498</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2345498</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Tue, 13 Aug 2013 11:30:41 GMT</pubDate></item><item><title><![CDATA[Reply to Return value on Tue, 13 Aug 2013 11:35:01 GMT]]></title><description><![CDATA[<p>Ich hätte normalerweise Dave Abrahams' Artikel-Serie<br />
<a href="http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/" rel="nofollow">http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/</a><br />
empfohlen, aber die Seite scheint (von mir aus zumindest) nicht mehr erreichbar zu sein.</p>
<p>Die Compiler können das mit den &quot;copy elisions&quot;, wobei &quot;return value optimization&quot; dazu gehört, schon sehr lange.</p>
<blockquote>
<p>Oder kann ich beruhigt große Objekte zurückgeben?</p>
</blockquote>
<p>Machen kannst du das. Ob Du das <em>beruhigt</em> machen kannst, weiß ich nicht. Copy elision wird nicht garantiert. Es ist eine optionale Optimierung, die von den populären Compilern unterstützt wird. Beruhigen würde mich das erst, wenn ich C++11 voraussetzen darf; denn dann ist garaniert, dass im Falle von so &quot;Handle-Klassen&quot; wie vector, nie in der Situation etwas unnötig kopiert wird. Im schlimmsten Fall wird &quot;ge-move-t&quot;, aber fast all die Container-Typen aus der Standardbibliothek (Ausnahme ist std::array), sind sehr effizient &quot;move-bar&quot;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2345500</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2345500</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Tue, 13 Aug 2013 11:35:01 GMT</pubDate></item><item><title><![CDATA[Reply to Return value on Tue, 13 Aug 2013 11:52:22 GMT]]></title><description><![CDATA[<p>Du solltest darauf achten, dass immer nur dasselbe Objekt zurückgegeben werden kann.</p>
<pre><code>vector&lt;VeryBig&gt; foo(){
    if (badcondition)
        return vector&lt;VeryBig&gt;();
    vector&lt;VeryBig&gt; v;
    // fill &quot;v&quot;
    return v;
}
</code></pre>
<p>Sowas macht die copy elision kaputt, zumindest wenn der Code noch etwas komplexer wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2345502</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2345502</guid><dc:creator><![CDATA[nwp3]]></dc:creator><pubDate>Tue, 13 Aug 2013 11:52:22 GMT</pubDate></item><item><title><![CDATA[Reply to Return value on Tue, 13 Aug 2013 12:14:29 GMT]]></title><description><![CDATA[<p>nwp3 schrieb:</p>
<blockquote>
<p>Du solltest darauf achten, dass immer nur dasselbe Objekt zurückgegeben werden kann.</p>
<pre><code>vector&lt;VeryBig&gt; foo(){
    if (badcondition)
        return vector&lt;VeryBig&gt;();
    vector&lt;VeryBig&gt; v;
    // fill &quot;v&quot;
    return v;
}
</code></pre>
<p>Sowas macht die copy elision kaputt, zumindest wenn der Code noch etwas komplexer wird.</p>
</blockquote>
<p>Stimmt. Das habe ich gerade hier gelesen:</p>
<p><a href="http://en.wikipedia.org/wiki/Return_value_optimization#Compiler_support" rel="nofollow">http://en.wikipedia.org/wiki/Return_value_optimization#Compiler_support</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2345507</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2345507</guid><dc:creator><![CDATA[Tomahawk]]></dc:creator><pubDate>Tue, 13 Aug 2013 12:14:29 GMT</pubDate></item></channel></rss>