<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.newlc.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>NewLC - auto_cleanup (an auto_ptr equivalent for R classes) - Comments</title>
 <link>http://www.newlc.com/en/auto-cleanup-auto-ptr-equivalent-r-classes</link>
 <description>Comments for &quot;auto_cleanup (an auto_ptr equivalent for R classes)&quot;</description>
 <language>en</language>
<item>
 <title>Re: auto_cleanup (an auto_ptr equivalent for R classes)</title>
 <link>http://www.newlc.com/en/auto-cleanup-auto-ptr-equivalent-r-classes#comment-41104</link>
 <description>&lt;p&gt;Note that s60v3 has support for c++ exceptions, so normal stack unwind calls dtors if object is in automatic (local) variable. This means that you can do auto_ptr and this trick here without cleanupstack.&lt;/p&gt;

&lt;p&gt;You can also get rid of two-phased construction (using auto_ptr member variables).&lt;/p&gt;

&lt;p&gt;NOTE: AFAIK, haven&#039;t actually tested these in practise.&lt;/p&gt;

&lt;p&gt;This might also interest people: &lt;a href=&quot;http://marcoplusplus.blogspot.com/2007/05/stlport-for-symbian-os-released.html&quot;&gt;http://marcoplusplus.blogspot.com/2007/05/stlport-for-symbian-os-released.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That should have working auto_ptr.&lt;/p&gt;</description>
 <pubDate>Tue, 28 Aug 2007 22:46:32 +0200</pubDate>
 <dc:creator>ssalmine</dc:creator>
 <guid isPermaLink="false">comment 41104 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: auto_cleanup (an auto_ptr equivalent for R classes)</title>
 <link>http://www.newlc.com/en/auto-cleanup-auto-ptr-equivalent-r-classes#comment-40983</link>
 <description>&lt;p&gt;Your are correct: For destructors that is obvious. I just wanted to point out that a programmer who uses auto_cleanup&lt;&gt; has to keep his eyes open for this condition. &lt;img src=&quot;/sites/all/modules/smileys/packs/example/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; /&gt;&lt;/p&gt;</description>
 <pubDate>Fri, 24 Aug 2007 10:46:48 +0200</pubDate>
 <dc:creator>makom</dc:creator>
 <guid isPermaLink="false">comment 40983 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: auto_cleanup (an auto_ptr equivalent for R classes)</title>
 <link>http://www.newlc.com/en/auto-cleanup-auto-ptr-equivalent-r-classes#comment-40981</link>
 <description>&lt;p&gt;&lt;div class=&quot;bb-quote&quot;&gt;&lt;blockquote class=&quot;bb-quote-body&quot;&gt;I think 99% of all cleanup methods take no arguments and return void. So I created a templated class TCleanupFunctor which makes the auto_cleanup class usefull for 99% of all the R classes.&lt;br /&gt;
&lt;/blockquote&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;All cleanup-functions should be argument-less and return void, or their design is broken.&lt;/p&gt;

&lt;p&gt;You can&#039;t have a cleanup-function return something, because that means you have to handle the return value some way...&lt;br /&gt;
cleanup-functions must always succeed, or they wont be useful in error handling...&lt;/p&gt;

&lt;p&gt;By the same logic, they must not take an argument, because this implicitly means the function might fail (because of a faulty argument)&lt;/p&gt;

&lt;p&gt;There is good reason destructors are argumentless and returns nothing &lt;img src=&quot;/sites/all/modules/smileys/packs/example/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;</description>
 <pubDate>Fri, 24 Aug 2007 10:06:21 +0200</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 40981 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: auto_cleanup (an auto_ptr equivalent for R classes)</title>
 <link>http://www.newlc.com/en/auto-cleanup-auto-ptr-equivalent-r-classes#comment-40957</link>
 <description>&lt;p&gt;Programming is subject to the same economic laws as are all other types of work. This means that 1) over time, people doing a certain kind of job need to become more productive, and 2) the more productive you are, the more money you can make.&lt;/p&gt;

&lt;p&gt;In the old days, people wrote assembly code themselves. Nowadays people use compilers. People using compilers are orders of magnitude more productive than people using assembly. A the time compilers became available, the discussion was that people should know what assembly code was generated, because it had to be fast, compact and whatnot. A discussion nobody is participating in anymore, for obvious reasons. &lt;/p&gt;

&lt;p&gt;The same can be said for the auto_ptr&lt;&gt; discussion. With auto_ptr&lt;&gt; and similar classes, you get automatic behaviour that can be coded explicitly by the programmer too. But why bother? The automatic code is good enough for almost everybody. Besides, that is counting when doing Symbian memory management is to use as little as possible. auto_ptr&lt;&gt; can be used as easily as cleanupstack calls. You can always put an auto_ptr&lt;&gt; var inside a local scope, for instance. And as in any computing situation, the algorithm used is much more important than some local decisions on the order of allocation and deallocation.&lt;/p&gt;

&lt;p&gt;Anyway, I never found the cleanupstack hard to use, not harder than similar schemes to protect you against resource leaks.&lt;/p&gt;

&lt;p&gt;auto_ptr&lt;&gt; can be implemented using the cleanupstack, so it is a way of abstacting the cleanupstack away, using Standard C++ constructs instead of Symbian C++ ones.&lt;/p&gt;

&lt;p&gt;Programmers should be carefull, but not only at the micro level. The macro level is much more important.&lt;/p&gt;

&lt;p&gt;auto_ptr&lt;&gt; can *not* be used to ditch Symbian C++ 2-phase construction, in the same way that the cleanup stack can not be used to ditch 2-phase construction. Personally, I would use 2-phase construction in portable code, because it makes destructors much easier to write. In Symbian C++ you are guarantueed that all member vars are initialised when the destructor is called, a luxury you do not have in Standard C++. &lt;/p&gt;

&lt;p&gt;Making code portable is an economic decision. &lt;/p&gt;

&lt;p&gt;Sander van der Wal&lt;br /&gt;
&lt;a href=&quot;http://www.mBrainSoftware.com&quot;&gt;www.mBrainSoftware.com&lt;/a&gt;&lt;/p&gt;</description>
 <pubDate>Thu, 23 Aug 2007 12:31:32 +0200</pubDate>
 <dc:creator>svdwal</dc:creator>
 <guid isPermaLink="false">comment 40957 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: auto_cleanup (an auto_ptr equivalent for R classes)</title>
 <link>http://www.newlc.com/en/auto-cleanup-auto-ptr-equivalent-r-classes#comment-40949</link>
 <description>&lt;p&gt;Agree with you Sander for most of the points....but not at one single point and this is &quot;leaving the programmer free to do usefull work.&quot; &lt;img src=&quot;/sites/all/modules/smileys/packs/example/wink.png&quot; title=&quot;Eye-wink&quot; alt=&quot;Eye-wink&quot; /&gt;. I think a programmer should always know what&#039;s the status of pointers/objects he/she uses in his/her application. This mean lazy in my opionion - leaving everything to compiler and forget about the lifetime af your objects &lt;img src=&quot;/sites/all/modules/smileys/packs/example/wink.png&quot; title=&quot;Eye-wink&quot; alt=&quot;Eye-wink&quot; /&gt; In fact, I think we can discuss a lot arround this subject &lt;img src=&quot;/sites/all/modules/smileys/packs/example/wink.png&quot; title=&quot;Eye-wink&quot; alt=&quot;Eye-wink&quot; /&gt;...and some of the point can be sumarized as:&lt;br /&gt;
- is indeed CleanupStack suck a difficult or usseless terminology that programmers keep complaining about it?&lt;br /&gt;
- is really auto_ptr a replacement for CleanupStack? (e.g. instead of putting smth on CS, programmer has to create aut_ptr)&lt;br /&gt;
- is it or is it not nattural that programmer should be so carerfull with memory management in Symbian environment? &lt;br /&gt;
- one good think about auto_ptr is that using it you can put all your object initialization in constructor (no more second phase construction needed)&lt;br /&gt;
- auto_ptr just hides CS &lt;img src=&quot;/sites/all/modules/smileys/packs/example/wink.png&quot; title=&quot;Eye-wink&quot; alt=&quot;Eye-wink&quot; /&gt;.....and in this case code portability is just a matter of design&lt;br /&gt;
&lt;/p&gt;</description>
 <pubDate>Thu, 23 Aug 2007 11:25:58 +0200</pubDate>
 <dc:creator>pirosl</dc:creator>
 <guid isPermaLink="false">comment 40949 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: auto_cleanup (an auto_ptr equivalent for R classes)</title>
 <link>http://www.newlc.com/en/auto-cleanup-auto-ptr-equivalent-r-classes#comment-40938</link>
 <description>&lt;p&gt;Thanks, for your comment maxxxpayne:&lt;/p&gt;

&lt;p&gt;Actually I did not know that such a templated class already exists. And yes the behaviour of TAutoClose an auto_cleanup&lt;&gt; is much the same. &lt;/p&gt;

&lt;p&gt;But there is a major difference between both:&lt;br /&gt;
TAutoClose is only usable for R classes which have a void Close(); function - auto_cleanup&lt;&gt; instead is agnostic of this method as long as the cleanupfunction takes no arguments and returns void (most cleanupfunctions fullfill this condition).&lt;/p&gt;

&lt;p&gt;A second reason for implementing auto_cleanup&lt;&gt; is that it shows a good example how you can use functors. Yes, there are very few reasons for using functors because M classes are used more often for similar reasons (callback interfaces - observers).&lt;/p&gt;</description>
 <pubDate>Thu, 23 Aug 2007 10:37:11 +0200</pubDate>
 <dc:creator>makom</dc:creator>
 <guid isPermaLink="false">comment 40938 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: auto_cleanup (an auto_ptr equivalent for R classes)</title>
 <link>http://www.newlc.com/en/auto-cleanup-auto-ptr-equivalent-r-classes#comment-40934</link>
 <description>&lt;p&gt;As I am responsible for creating the Symbian C++ auto_ptr&lt;&gt; class, some comments:&lt;/p&gt;

&lt;p&gt;auto_ptr&lt;&gt; is meant to make code portable between different C++ implementation while having full protection against resource leaks. Such code isn&#039;t likely to have much dependency on specific Symbian C++ constructs (such as the cleanup stack), in fact, these dependencies must be eliminated to make the code portable. &lt;/p&gt;

&lt;p&gt;It does mean that you cannot mix explicit use of the cleanupstack and implicit use using auto_ptr&lt;&gt; and auto_cleanup&lt;&gt;. But that isn&#039;t a disadvantage. If you want portable code, explicit use of the cleanup stack is out of the question. &lt;/p&gt;

&lt;p&gt;Therefore, a NewLC method is not likely to be found in portable code. Portable code will instead have some factory function that returns an auto_ptr&lt;&gt; or auto_cleanup&lt;&gt; variable.&lt;/p&gt;

&lt;p&gt;Having to do one&#039;s own popping of the cleanup stack means that it is possible to mess this up. You can protect yourself against that by using the CleanupStack::PopAndDestroy() overload that checks whether the passed pointer is the one you would expect. But this is a kludge. With auto_ptr&lt;&gt; and auto_cleanup&lt;&gt; the compiler takes care of destruction, leaving the programmer free to do usefull work. So the programmer becomes more efficient, which is a good thing. This has nothing to do with being lazy. Writing code in such a way certain errors cannot occur is the hallmark of a good programmer.&lt;/p&gt;

&lt;p&gt;Sander van der Wal&lt;br /&gt;
&lt;a href=&quot;http://www.mBrainSoftware.com&quot;&gt;www.mBrainSoftware.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;</description>
 <pubDate>Thu, 23 Aug 2007 09:07:16 +0200</pubDate>
 <dc:creator>svdwal</dc:creator>
 <guid isPermaLink="false">comment 40934 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: auto_cleanup (an auto_ptr equivalent for R classes)</title>
 <link>http://www.newlc.com/en/auto-cleanup-auto-ptr-equivalent-r-classes#comment-40924</link>
 <description>&lt;p&gt;Since you have tagged this article for beginners, I believe that you should have discussed TAutoClose also and a comparison of advantage/disadvantage of both approaches. &lt;/p&gt;

&lt;p&gt;While not sophisticated as your implementation, it does get the job done, both for auto and member types.&lt;/p&gt;</description>
 <pubDate>Wed, 22 Aug 2007 20:44:10 +0200</pubDate>
 <dc:creator>maxxxpayne</dc:creator>
 <guid isPermaLink="false">comment 40924 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: auto_cleanup (an auto_ptr equivalent for R classes)</title>
 <link>http://www.newlc.com/en/auto-cleanup-auto-ptr-equivalent-r-classes#comment-40923</link>
 <description>&lt;p&gt;@pirosl: You are absolutely right:&lt;br /&gt;
Using these classes has a runtime overhead because of the additional created objects. You have to evaluate readability and toughness against performance of your code. &lt;br /&gt;
Mixing the usage of auto_ptr/auto_cleanup and using the cleanupstack in a conventional way will end in a mess. Thats why you should use auto_ptr/auto_cleanup only if you are familiar with the conventional techniques of the cleanupstack. If this is the case using auto_ptr/auto_cleanup can be very usefull. As the name says these classes should be only used for automatic variables - not for member variables! Exactly like the cleanupstack - this is not used for member variables too. &lt;img src=&quot;/sites/all/modules/smileys/packs/example/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; /&gt;&lt;/p&gt;</description>
 <pubDate>Wed, 22 Aug 2007 18:26:53 +0200</pubDate>
 <dc:creator>makom</dc:creator>
 <guid isPermaLink="false">comment 40923 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: auto_cleanup (an auto_ptr equivalent for R classes)</title>
 <link>http://www.newlc.com/en/auto-cleanup-auto-ptr-equivalent-r-classes#comment-40922</link>
 <description>&lt;p&gt;Very nice article. As a personal opinion, auto_ptr are a very nice feature sometimes (for lazy developers &lt;img src=&quot;/sites/all/modules/smileys/packs/example/wink.png&quot; title=&quot;Eye-wink&quot; alt=&quot;Eye-wink&quot; /&gt; ). It&#039;s very convenient to know that your pointer will be destroyed when auto_ptr is out of scope, but besides that there are a lot of drawnbacks.&lt;br /&gt;
For example:&lt;br /&gt;
- you can&#039;t implement NewLC using auto_ptr (or at least not returning a pointer to your object)&lt;br /&gt;
- by using CleanupStack::PopAndDestroy() you can check if the poped object is the one you want; you can&#039;t do this with auto_ptr&lt;br /&gt;
- using auto_ptr implies you create an extra object every time you want to use it (i know it&#039;s a small object...but &lt;img src=&quot;/sites/all/modules/smileys/packs/example/wink.png&quot; title=&quot;Eye-wink&quot; alt=&quot;Eye-wink&quot; /&gt; ).....you can have same powerfull behaviour using CleanupStack::PushL(TCleanupItem).....and may be sometime it&#039;s worth it.&lt;br /&gt;
- a big disadvantage is that CleanupStack is not fully replaceable....eg. you can&#039;t have a medium-big project and work only with auto_ptr....so eventually you&#039;ll end up mixing auto_ptr with CS&lt;br /&gt;
&lt;/p&gt;</description>
 <pubDate>Wed, 22 Aug 2007 18:05:56 +0200</pubDate>
 <dc:creator>pirosl</dc:creator>
 <guid isPermaLink="false">comment 40922 at http://www.newlc.com</guid>
</item>
<item>
 <title>auto_cleanup (an auto_ptr equivalent for R classes)</title>
 <link>http://www.newlc.com/en/auto-cleanup-auto-ptr-equivalent-r-classes</link>
 <description>&lt;p&gt;An implemetation for cleaning up an instance of Symbians typical R classes automatically. As we all know an instance of an R class usually has to be cleaned up via a call to a certain cleanup method (e.g. Close(), Disconnect(), Release() etc.) For implementing the auto_cleanup class which should be agnostic of this cleanup method I have choosen to use a functor class...&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://www.newlc.com/en/auto-cleanup-auto-ptr-equivalent-r-classes&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://www.newlc.com/en/auto-cleanup-auto-ptr-equivalent-r-classes#comments</comments>
 <category domain="http://www.newlc.com/en/taxonomy/term/1">Basics</category>
 <enclosure url="http://www.newlc.com/files/auto_cleanup.h" length="5099" type="text/plain" />
 <pubDate>Wed, 22 Aug 2007 15:47:05 +0200</pubDate>
 <dc:creator>makom</dc:creator>
 <guid isPermaLink="false">18722 at http://www.newlc.com</guid>
</item>
</channel>
</rss>
