<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 善用 swap 塞資料進 container</title>
	<atom:link href="http://www.jeffhung.net/blog/articles/jeffhung/1171/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jeffhung.net/blog/articles/jeffhung/1171/</link>
	<description>(My smile insists of having nose. :-)</description>
	<lastBuildDate>Mon, 26 Jul 2010 16:16:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: verbalsaint</title>
		<link>http://www.jeffhung.net/blog/articles/jeffhung/1171/comment-page-1/#comment-123436</link>
		<dc:creator>verbalsaint</dc:creator>
		<pubDate>Thu, 27 Nov 2008 01:18:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeffhung.net/blog/?p=1171#comment-123436</guid>
		<description>It has been mentioned in effective c++3rd item 25</description>
		<content:encoded><![CDATA[<p>It has been mentioned in effective c++3rd item 25</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: augustinus</title>
		<link>http://www.jeffhung.net/blog/articles/jeffhung/1171/comment-page-1/#comment-109593</link>
		<dc:creator>augustinus</dc:creator>
		<pubDate>Wed, 20 Aug 2008 05:11:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeffhung.net/blog/?p=1171#comment-109593</guid>
		<description>果然本篇引起熱烈迴響 XD

來提一下我在 IRC 裡跟 jeffhung 討論過的意見：

其實前陣子我就碰過 av 提到的寫法，但我最後決定改掉它，回歸原始操作方式。因為......

 1. 沒有 profiling 無法證明這樣真能有幫助；事實上，在最近我碰到的另一個類似案例中，profiling 結果發現 bottleneck 總是在 I/O 處，而且遠大於 push_back() 及其相應的 copy constructor/assignment, 無法透過上述 reference 操作或是 reserve 來改善。

 2. 在 1. 的前提下，可讀性及日後維護的其他考量遠比這類最佳化更重要。尤其是第五則 comment 也提到了，只要換個 container 事情就不同了。

 3. 如果再多為將來可能接管的新手想一點，寧可先假裝所有的 container 和 copy constructor 都支援 reference 操作和 copy-on-write.</description>
		<content:encoded><![CDATA[<p>果然本篇引起熱烈迴響 XD</p>
<p>來提一下我在 IRC 裡跟 jeffhung 討論過的意見：</p>
<p>其實前陣子我就碰過 av 提到的寫法，但我最後決定改掉它，回歸原始操作方式。因為......</p>
<p> 1. 沒有 profiling 無法證明這樣真能有幫助；事實上，在最近我碰到的另一個類似案例中，profiling 結果發現 bottleneck 總是在 I/O 處，而且遠大於 push_back() 及其相應的 copy constructor/assignment, 無法透過上述 reference 操作或是 reserve 來改善。</p>
<p> 2. 在 1. 的前提下，可讀性及日後維護的其他考量遠比這類最佳化更重要。尤其是第五則 comment 也提到了，只要換個 container 事情就不同了。</p>
<p> 3. 如果再多為將來可能接管的新手想一點，寧可先假裝所有的 container 和 copy constructor 都支援 reference 操作和 copy-on-write.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jeffhung</title>
		<link>http://www.jeffhung.net/blog/articles/jeffhung/1171/comment-page-1/#comment-109559</link>
		<dc:creator>jeffhung</dc:creator>
		<pubDate>Wed, 20 Aug 2008 02:08:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeffhung.net/blog/?p=1171#comment-109559</guid>
		<description>av,

這篇的 split() 是我掰出來的假想函式，不是 boost::split()。</description>
		<content:encoded><![CDATA[<p>av,</p>
<p>這篇的 split() 是我掰出來的假想函式，不是 boost::split()。</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jeffhung</title>
		<link>http://www.jeffhung.net/blog/articles/jeffhung/1171/comment-page-1/#comment-109557</link>
		<dc:creator>jeffhung</dc:creator>
		<pubDate>Wed, 20 Aug 2008 02:06:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeffhung.net/blog/?p=1171#comment-109557</guid>
		<description>fr3@K,

謝謝，用 back() 確實比較簡潔易懂。不過若是其他的 container 如 set，那可能就要用 a_set.insert(vector&lt;line&gt;()).first-&gt;swap(tokens); 了。</description>
		<content:encoded><![CDATA[<p>fr3@K,</p>
<p>謝謝，用 back() 確實比較簡潔易懂。不過若是其他的 container 如 set，那可能就要用 a_set.insert(vector&lt;line&gt;()).first->swap(tokens); 了。</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Slimek</title>
		<link>http://www.jeffhung.net/blog/articles/jeffhung/1171/comment-page-1/#comment-109550</link>
		<dc:creator>Slimek</dc:creator>
		<pubDate>Wed, 20 Aug 2008 01:21:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeffhung.net/blog/?p=1171#comment-109550</guid>
		<description>或許這樣寫也可以：

csv_data.push_back( vector() );
split( line, &quot;,&quot;, csv_data.back() );</description>
		<content:encoded><![CDATA[<p>或許這樣寫也可以：</p>
<p>csv_data.push_back( vector() );<br />
split( line, ",", csv_data.back() );</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: av</title>
		<link>http://www.jeffhung.net/blog/articles/jeffhung/1171/comment-page-1/#comment-109402</link>
		<dc:creator>av</dc:creator>
		<pubDate>Tue, 19 Aug 2008 16:36:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeffhung.net/blog/?p=1171#comment-109402</guid>
		<description>用不著 sawp 吧：
csv_data.push_back(vector()); // 一樣
split(line, &quot;,&quot;, csv_data.back()); // 直接 split 進 cvs_data 的最後一個元素.

不過你的 split 是哪裡的啊? 跟 boost 不一樣：
boost::split(csv_data.back(), line, is_any_of(&quot;,&quot;));</description>
		<content:encoded><![CDATA[<p>用不著 sawp 吧：<br />
csv_data.push_back(vector()); // 一樣<br />
split(line, ",", csv_data.back()); // 直接 split 進 cvs_data 的最後一個元素.</p>
<p>不過你的 split 是哪裡的啊? 跟 boost 不一樣：<br />
boost::split(csv_data.back(), line, is_any_of(","));</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fr3@K</title>
		<link>http://www.jeffhung.net/blog/articles/jeffhung/1171/comment-page-1/#comment-109243</link>
		<dc:creator>fr3@K</dc:creator>
		<pubDate>Tue, 19 Aug 2008 07:38:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeffhung.net/blog/?p=1171#comment-109243</guid>
		<description>BTW, C++0x 的 sequence container 都有支援 rvalue reference. 以後就不需要這種 two stage push_back 了.

void push_back(T&amp;&amp; x);</description>
		<content:encoded><![CDATA[<p>BTW, C++0x 的 sequence container 都有支援 rvalue reference. 以後就不需要這種 two stage push_back 了.</p>
<p>void push_back(T&amp;&amp; x);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fr3@K</title>
		<link>http://www.jeffhung.net/blog/articles/jeffhung/1171/comment-page-1/#comment-109241</link>
		<dc:creator>fr3@K</dc:creator>
		<pubDate>Tue, 19 Aug 2008 07:31:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeffhung.net/blog/?p=1171#comment-109241</guid>
		<description>csv_data.back().swap(tokens);</description>
		<content:encoded><![CDATA[<p>csv_data.back().swap(tokens);</p>
]]></content:encoded>
	</item>
</channel>
</rss>
