<?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: Don&#8217;t try for exception safety</title>
	<atom:link href="http://ccgi.hashpling.plus.com/blog/dont-try-for-exception-safety/feed/" rel="self" type="application/rss+xml" />
	<link>http://ccgi.hashpling.plus.com/blog/dont-try-for-exception-safety/</link>
	<description>Don't worry, I've hidden all the complexity behind a macro.</description>
	<lastBuildDate>Tue, 19 May 2009 10:43:05 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: hashpling</title>
		<link>http://ccgi.hashpling.plus.com/blog/dont-try-for-exception-safety/comment-page-1/#comment-161</link>
		<dc:creator>hashpling</dc:creator>
		<pubDate>Fri, 21 Dec 2007 22:25:22 +0000</pubDate>
		<guid isPermaLink="false">http://ccgi.hashpling.plus.com/blog/dont-try-for-exception-safety/#comment-161</guid>
		<description>There is no &#039;finally&#039; in C++, it&#039;s just Java, AFAIK.

And yes, you could just use a std::vector&lt; char &gt; as it&#039;s guaranteed that vector elements are stored contiguously.  For some reason I feel that relying on this guaranteed &quot;implementation detail&quot; is a bit too intrusive, but I&#039;m not sure why I feel that way as it is a guarantee that can be usefully relied on.

So you could have:
&lt;pre&gt;std::vector&lt;char&gt; buffer( bufsize );&lt;/pre&gt;

and:
&lt;pre&gt;DoConversion( &amp;buffer[0], bufsize, test_data, test_len );&lt;/pre&gt;

Anyway, in the next version of C++ we will get std::unique_ptr to replace auto_ptr which will have a customizable deleter and so will support correctly deleting dynamically allocated arrays.</description>
		<content:encoded><![CDATA[<p>There is no &#8216;finally&#8217; in C++, it&#8217;s just Java, AFAIK.</p>
<p>And yes, you could just use a std::vector< char > as it&#8217;s guaranteed that vector elements are stored contiguously.  For some reason I feel that relying on this guaranteed &#8220;implementation detail&#8221; is a bit too intrusive, but I&#8217;m not sure why I feel that way as it is a guarantee that can be usefully relied on.</p>
<p>So you could have:</p>
<pre>std::vector<char> buffer( bufsize );</char></pre>
<p>and:</p>
<pre>DoConversion( &#038;buffer[0], bufsize, test_data, test_len );</pre>
<p>Anyway, in the next version of C++ we will get std::unique_ptr to replace auto_ptr which will have a customizable deleter and so will support correctly deleting dynamically allocated arrays.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://ccgi.hashpling.plus.com/blog/dont-try-for-exception-safety/comment-page-1/#comment-160</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Fri, 21 Dec 2007 20:56:09 +0000</pubDate>
		<guid isPermaLink="false">http://ccgi.hashpling.plus.com/blog/dont-try-for-exception-safety/#comment-160</guid>
		<description>I was so nearly tempted to recommend std::auto_ptr, but of course that doesn&#039;t cope well at all with arrays.  Herb Sutter has &lt;a href=&quot;http://www.gotw.ca/gotw/042.htm&quot; rel=&quot;nofollow&quot;&gt;a GotW&lt;/a&gt; dealing with exactly this topic: why not just use std::vector?</description>
		<content:encoded><![CDATA[<p>I was so nearly tempted to recommend std::auto_ptr, but of course that doesn&#8217;t cope well at all with arrays.  Herb Sutter has <a href="http://www.gotw.ca/gotw/042.htm" rel="nofollow">a GotW</a> dealing with exactly this topic: why not just use std::vector?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darren</title>
		<link>http://ccgi.hashpling.plus.com/blog/dont-try-for-exception-safety/comment-page-1/#comment-159</link>
		<dc:creator>Darren</dc:creator>
		<pubDate>Fri, 21 Dec 2007 11:10:14 +0000</pubDate>
		<guid isPermaLink="false">http://ccgi.hashpling.plus.com/blog/dont-try-for-exception-safety/#comment-159</guid>
		<description>Forgive my ignorance, but doesn&#039;t C++ have a &quot;finally&quot; clause to deal with the deallocation?

Pseudocde:
try
{
    // allocate memory
}
catch 
{
    // log error
}
finally
{
    // deallocate
}

Note that finally is always called, whether exceptions are thrown or not.

That&#039;s how it works in Java-land and they based it all on C++ right?

Or have I misread it and you only want it deallocated if there is an exception?</description>
		<content:encoded><![CDATA[<p>Forgive my ignorance, but doesn&#8217;t C++ have a &#8220;finally&#8221; clause to deal with the deallocation?</p>
<p>Pseudocde:<br />
try<br />
{<br />
    // allocate memory<br />
}<br />
catch<br />
{<br />
    // log error<br />
}<br />
finally<br />
{<br />
    // deallocate<br />
}</p>
<p>Note that finally is always called, whether exceptions are thrown or not.</p>
<p>That&#8217;s how it works in Java-land and they based it all on C++ right?</p>
<p>Or have I misread it and you only want it deallocated if there is an exception?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
