<?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 - RPointerArray and CleanupStack - Comments</title>
 <link>http://www.newlc.com/forum/rpointerarray-and-cleanupstack</link>
 <description>Comments for &quot;RPointerArray and CleanupStack&quot;</description>
 <language>en</language>
<item>
 <title>Re: RPointerArray and CleanupStack</title>
 <link>http://www.newlc.com/forum/rpointerarray-and-cleanupstack#comment-45832</link>
 <description>&lt;p&gt;OK, just to return to the issue of allocating R objects in the heap, just check out this new article on Symbian DevNet: &lt;a href=&quot;http://developer.symbian.com/main/downloads/papers/advanced_RArray.pdf&quot;&gt;http://developer.symbian.com/main/downloads/papers/advanced_RArray.pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It has a chapter on this issue...&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;</description>
 <pubDate>Tue, 15 Apr 2008 21:35:55 +0200</pubDate>
 <dc:creator>Andreas</dc:creator>
 <guid isPermaLink="false">comment 45832 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: RPointerArray and CleanupStack</title>
 <link>http://www.newlc.com/forum/rpointerarray-and-cleanupstack#comment-45733</link>
 <description>&lt;p&gt;Could you please point me to the place in the documentation where it says that R-objects should be allocated on the stack?&lt;br /&gt;
I can&#039;t find it. &lt;br /&gt;
In the &quot;class types&quot; section, they don&#039;t say a word of where you should keep them.&lt;/p&gt;

&lt;p&gt;I agree that it apparently is not obvious that member variables of objects allocated on the heap is also on the heap.&lt;/p&gt;

&lt;p&gt;But don&#039;t you think its gets even more confusing for the &quot;newbies&quot; when a lot of &quot;experts&quot; reiterate that &quot;R-Objects should be on the stack&quot; and then almost every example and real usage has them as member variables of CBase objects? And indeed this way usually produces the most simple and easy-to-maintain code?&lt;br /&gt;
Don&#039;t really promote understanding &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>Mon, 14 Apr 2008 09:53:12 +0200</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 45733 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: RPointerArray and CleanupStack</title>
 <link>http://www.newlc.com/forum/rpointerarray-and-cleanupstack#comment-45753</link>
 <description>&lt;p&gt;&lt;div class=&quot;bb-quote&quot;&gt;&lt;blockquote class=&quot;bb-quote-body&quot;&gt;Could you please point me to the place in the documentation where it says that R-objects should be allocated on the stack?&lt;br /&gt;
I can&#039;t find it. &lt;/blockquote&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;I believe we all agree on this issue already.&lt;/p&gt;

&lt;p&gt;The point is that you shouldn&#039;t dynamically allocate R objects using new (ELeave).&lt;/p&gt;

&lt;p&gt;That I guess we also agree. No point in continuing, since no one else participates this discussion anymore  &lt;img src=&quot;/sites/all/modules/smileys/packs/example/wink.png&quot; title=&quot;Eye-wink&quot; alt=&quot;Eye-wink&quot; /&gt; &lt;/p&gt;</description>
 <pubDate>Sat, 12 Apr 2008 18:11:15 +0200</pubDate>
 <dc:creator>Andreas</dc:creator>
 <guid isPermaLink="false">comment 45753 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: RPointerArray and CleanupStack</title>
 <link>http://www.newlc.com/forum/rpointerarray-and-cleanupstack#comment-45722</link>
 <description>&lt;p&gt;When people say RObjects should live on the stack, and indeed when the documentation says that, it is actually incorrect from a literal point of view in the interpretation of English, but think of it as a phrase, and what it actually means is they are not intended to be directly allocated on the heap.  The SDK says this and they should be chastised for doing so and it should be re-written to be accurate, as I should be castised for saying not on the stack in my original posting when I meant not directly allocated on the heap which is what I meant 6to say.&lt;/p&gt;

&lt;p&gt;R objects can go:&lt;br /&gt;
a) be allocated on the heap directly &lt;br /&gt;
b) be allocated on the heap indirectly because they are members of a C class&lt;br /&gt;
c) be on the stack. &lt;/p&gt;

&lt;p&gt;They are intended for use as b or c. &lt;/p&gt;

&lt;p&gt;a) is possible and there is nothing to stop you  from doing so, and you will even find examples in the Symbian source code where they are (just becasue you see something in Symbian doesn&#039;t mean it is correct, there are lots of examples of bad programing in Symbian code).&lt;br /&gt;
Howeverif you allocate an R object on the heap directly then frequently making it leave safe can become more complex. &lt;span style=&quot;font-weight:bold&quot;&gt;So while it is possible to allocate them directly on the heap, if this makes things more complex than not directly allocating them on the heap, then what is the point in choosing complexity  when you can choose simplicity?&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;Alh, I didn&#039;t do a good job of saying why newbies could be more confused now - because newbies quite often don&#039;t know if a nested object inside a C object is on the stack or the heap. Its obvious to us that it is, but from seeing many people&#039;s postings in the past its obvious its not obvious to newbies or numpties.&lt;/p&gt;

&lt;p&gt;As should be obvious from what I have previously said, and what Alh has stated explicitly - the bad code of the original function is causing bad ripples throughout the rest of the code. &lt;br /&gt;
if it better to fix that function rather than work around it. &lt;br /&gt;
&lt;/p&gt;</description>
 <pubDate>Thu, 10 Apr 2008 22:12:52 +0200</pubDate>
 <dc:creator>Numpty Alert</dc:creator>
 <guid isPermaLink="false">comment 45722 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: RPointerArray and CleanupStack</title>
 <link>http://www.newlc.com/forum/rpointerarray-and-cleanupstack#comment-45717</link>
 <description>&lt;p&gt;Or do as I fixed, pop it out in the FillArrayL as I originally intented. Fixed it to the code. Optionally do as alh said.&lt;/p&gt;</description>
 <pubDate>Thu, 10 Apr 2008 14:17:18 +0200</pubDate>
 <dc:creator>Andreas</dc:creator>
 <guid isPermaLink="false">comment 45717 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: RPointerArray and CleanupStack</title>
 <link>http://www.newlc.com/forum/rpointerarray-and-cleanupstack#comment-45709</link>
 <description>&lt;p&gt;OK, OK I confess being too vague about the R -classes. You do not need to &quot;allocate them on the stack&quot; but as already said, you usually shouldn&#039;t dynamically allocate them (though you can; see e.g. Babin: Developing Software for Symbian OS, 2nd Ed, p. 76).&lt;/p&gt;

&lt;p&gt;What your example here does is that it actually fills a RPointerArray with objects for the caller. Why not avoid the dynamic allocation of R object like this:&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;void CUtils::FillArrayL(TInt aCount, RPointerArray&amp;lt;CMyClass&amp;gt; &amp;amp; aArray)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; aArray.ResetAndDestroy(); // Optional if the array should be emptied first. Caller could do this too.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupResetAndDestroyPushL(aArray);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(TInt ct = 0; ct &amp;lt; Count; ct++)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CMyClass *myClass = CMyClass::NewL(ct);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupStack::PushL(myClass);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; aArray.AppendL(myClass);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupStack::Pop();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupStack::Pop(); // Thanks, alh, for pointing out this one.&lt;br /&gt;}&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;Now you do not have to do dynamic allocation in order to return a local object from the method. Let the caller take care of the construction of the array object.&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;void&amp;nbsp; CUtils::UseArrayL()&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RPointerArray&amp;lt;CMyClass&amp;gt; myArray;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FillArrayL(10, myArray);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* do something, and if it can leave, push myArray to cleanup stack again! */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mArray.ResetAndDestroy();&lt;br /&gt;}&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;See, no need to dynamically allocate RPointerArray, much simpler code to use.&lt;/p&gt;</description>
 <pubDate>Thu, 10 Apr 2008 14:15:55 +0200</pubDate>
 <dc:creator>Andreas</dc:creator>
 <guid isPermaLink="false">comment 45709 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: RPointerArray and CleanupStack</title>
 <link>http://www.newlc.com/forum/rpointerarray-and-cleanupstack#comment-45712</link>
 <description>&lt;p&gt;Just one note, the FillArrayL in andreas post should be named FillArrayLC (since it leaves a cleanupitem on the cleanupstack)&lt;/p&gt;

&lt;p&gt;And you would have to do either:&lt;/p&gt;

&lt;p&gt;&lt;pre class=&quot;bb-code-block&quot;&gt;
CleanupStack::Pop()
mArray.ResetAndDestroy();
&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;or simply:&lt;/p&gt;

&lt;p&gt;&lt;pre class=&quot;bb-code-block&quot;&gt;
CleanupStack::PopAndDestroy()
&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;to empty it in the end of UseArrayL&lt;/p&gt;</description>
 <pubDate>Thu, 10 Apr 2008 13:15:07 +0200</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 45712 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: RPointerArray and CleanupStack</title>
 <link>http://www.newlc.com/forum/rpointerarray-and-cleanupstack#comment-45698</link>
 <description>&lt;p&gt;&lt;div class=&quot;bb-quote&quot;&gt;&lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;br /&gt;
Alh you&#039;re right you&#039;ve confused them even more.&lt;br /&gt;
&lt;/blockquote&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;Well, imho, what is confusing is everyone reiterating this falsehood about &quot;R-classes are supposed to live on the stack&quot;.&lt;br /&gt;
Its just not true at all, and just very confusing for people trying to understand how it really works.&lt;/p&gt;

&lt;p&gt;What is true though is that they are _not_ supposed to be owned via a pointer, and you should _not_ use new to create them.&lt;/p&gt;

&lt;p&gt;But that does _not_ mean &quot;they should be on the stack&quot;.... &lt;br /&gt;
Contrary to CBase objects they _can_ be put on the stack, but that is very far from &quot;they have to be on the stack&quot;.&lt;/p&gt;

&lt;p&gt;But... just to be extra clear:&lt;br /&gt;
You should go to your architect or whoever decided that function signature and tell him it is a bad design, and why, and convince him to change it.&lt;br /&gt;
It has a faulty design, and will create a lot of extra work for you (which you have already started to notice) and probably be a source of a few defects...&lt;br /&gt;
&lt;/p&gt;</description>
 <pubDate>Thu, 10 Apr 2008 09:41:56 +0200</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 45698 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: RPointerArray and CleanupStack</title>
 <link>http://www.newlc.com/forum/rpointerarray-and-cleanupstack#comment-45689</link>
 <description>&lt;p&gt;I qoute from Andreas&#039; post:&lt;br /&gt;
&lt;div class=&quot;bb-quote&quot;&gt;&lt;blockquote class=&quot;bb-quote-body&quot;&gt;As R classes are designed not to be dynamically allocated, why do it when you can live without it?!&lt;/blockquote&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;You can continue to hit your head with a hammer, but why should you?&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;</description>
 <pubDate>Thu, 10 Apr 2008 06:41:13 +0200</pubDate>
 <dc:creator>rbrunner</dc:creator>
 <guid isPermaLink="false">comment 45689 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: RPointerArray and CleanupStack</title>
 <link>http://www.newlc.com/forum/rpointerarray-and-cleanupstack#comment-45688</link>
 <description>&lt;p&gt;Hi, &lt;/p&gt;

&lt;p&gt;To make every one clear it is not at all a strict convention to allocate a R based object on stack, even the R object itself uses heap internally when u call Append or insert in case of &lt;br /&gt;
RPointerArray so no confusion about stack or heap both work &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;Now &lt;br /&gt;
mac123&lt;/p&gt;

&lt;p&gt;As you can see the method &lt;br /&gt;
CleanupResetAndDestroyPushL( pMyArray); is in #include &quot;mmfcontrollerpluginresolver.h&quot; which is a specific to &lt;span style=&quot;font-weight:bold&quot;&gt;MMF&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;so it is as good as saying that &lt;span style=&quot;font-weight:bold&quot;&gt;MMF&lt;/span&gt; has written its own cleanp operation CleanupResetAndDestroyPushL( pMyArray); &lt;/p&gt;

&lt;p&gt;So I think internally he is also using the same TCleanupItem solution which i gave you.&lt;/p&gt;

&lt;p&gt;It is always better to ve your own cleanup operation.&lt;/p&gt;

&lt;p&gt;So just use the second one to better understanding and correct cleanup &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>Thu, 10 Apr 2008 06:39:54 +0200</pubDate>
 <dc:creator>prajwal.r.m</dc:creator>
 <guid isPermaLink="false">comment 45688 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: RPointerArray and CleanupStack</title>
 <link>http://www.newlc.com/forum/rpointerarray-and-cleanupstack#comment-45686</link>
 <description>&lt;p&gt;hello guys,&lt;/p&gt;

&lt;p&gt;I am totally lost now.. &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;From the discussion we had here, I understood that there is nothing wrong in allocating RPOinterArray on stack or heap.. Only thing is that we should be cautious to call ResetAndDestroy, Close on RPointerArray..  Also we need to delete the RPointerArray Pointer..  Is that my understanding correct ??&lt;/p&gt;

&lt;p&gt;And there are basically 2 ways to implement the cleanupStack.  1/ CleanupResetAndDestroyPushL and 2/ TCleanUpItem.     which one is the preferred solution ?&lt;/p&gt;

&lt;p&gt;Just to summarize, I will put both the solution here..&lt;/p&gt;

&lt;p&gt;1/CleanupResetAndDestroyPushL &lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;#include &amp;quot;mmfcontrollerpluginresolver.h&amp;quot;&lt;br /&gt;&lt;br /&gt;RPointerArray&amp;lt;CMyClass&amp;gt;*&amp;nbsp; CUtils::CreateRpointerL(TInt Count)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RPointerArray&amp;lt;CMyClass&amp;gt; *pMyArray = new (ELeave)RPointerArray&amp;lt;CMyClass&amp;gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupResetAndDestroyPushL( pMyArray);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(TInt ct = 0; ct &amp;lt; Count; ct++)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CMyClass *myClass = CMyClass::NewL(ct);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupStack::PushL(myClass);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (*pMyArray).AppendL(myClass);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupStack::Pop();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupStack::Pop();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return pMyArray;&lt;br /&gt;}&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;2/ Using TCleanupItem&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;void CleanupResetAndDestroy(TAny*&amp;nbsp; aItem)&lt;br /&gt;{&lt;br /&gt;RPointerArray&amp;lt;CMyClass&amp;gt; *pMyArray = (RPointerArray&amp;lt;CMyClass&amp;gt;*) aItem;&lt;br /&gt;pMyArray-&amp;gt;ResetAndDestroy();&lt;br /&gt;pMyArray-&amp;gt;Close();&lt;br /&gt;delete&amp;nbsp; pMyArray;&lt;br /&gt;}&lt;br /&gt;RPointerArray&amp;lt;CMyClass&amp;gt;*&amp;nbsp; CUtils::CreateRpointerL(TInt Count)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RPointerArray&amp;lt;CMyClass&amp;gt; *pMyArray = new (ELeave)RPointerArray&amp;lt;CMyClass&amp;gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupStack::PushL(TCleanupItem(CleanupResetAndDestroy(pMyArray ));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(TInt ct = 0; ct &amp;lt; Count; ct++)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CMyClass *myClass = CMyClass::NewL(ct);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupStack::PushL(myClass);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (*pMyArray).AppendL(myClass);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupStack::Pop();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return pMyArray;&lt;br /&gt;&amp;nbsp;&amp;nbsp; CleanupStack::Pop();&lt;br /&gt;}&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;Thanks&lt;br /&gt;
Mac&lt;/p&gt;</description>
 <pubDate>Thu, 10 Apr 2008 03:58:28 +0200</pubDate>
 <dc:creator>mac123</dc:creator>
 <guid isPermaLink="false">comment 45686 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: RPointerArray and CleanupStack</title>
 <link>http://www.newlc.com/forum/rpointerarray-and-cleanupstack#comment-45682</link>
 <description>&lt;p&gt;Alh you&#039;re right you&#039;ve confused them even more.&lt;/p&gt;

&lt;p&gt;That unchangeable function signature is incorrect by the way, there is no trailing L in its name to indicate it is a leaving function. And there is a memory leak if AppendL() leaves. So if that function can&#039;t be changed then whats the point of making the calling code leave safe if the function its calling isn&#039;t itself leave safe?&lt;/p&gt;</description>
 <pubDate>Wed, 09 Apr 2008 19:40:29 +0200</pubDate>
 <dc:creator>Numpty Alert</dc:creator>
 <guid isPermaLink="false">comment 45682 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: RPointerArray and CleanupStack</title>
 <link>http://www.newlc.com/forum/rpointerarray-and-cleanupstack#comment-45678</link>
 <description>&lt;p&gt;I can&#039;t remember having my RPointerArrays on the stack, ever.&lt;/p&gt;

&lt;p&gt;I keep them as a member variable of a CBase object, thus... on the heap.&lt;/p&gt;

&lt;p&gt;Though, you are right you shouldn&#039;t use new explicitly to create it....&lt;/p&gt;

&lt;p&gt;Just wanted to confuse everyone some more  &lt;img src=&quot;/sites/all/modules/smileys/packs/example/tongue.png&quot; title=&quot;Sticking out tongue&quot; alt=&quot;Sticking out tongue&quot; /&gt; &lt;/p&gt;</description>
 <pubDate>Wed, 09 Apr 2008 17:05:30 +0200</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 45678 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: RPointerArray and CleanupStack</title>
 <link>http://www.newlc.com/forum/rpointerarray-and-cleanupstack#comment-45664</link>
 <description>&lt;p&gt;&lt;div class=&quot;bb-quote&quot;&gt;&lt;blockquote class=&quot;bb-quote-body&quot;&gt;You are absolutely right, there is no such restriction on RPointerArray that it has to be allocated on to the stack.&lt;/blockquote&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;But it will make things more complex. As R classes are &lt;span style=&quot;font-weight:bold&quot;&gt;designed&lt;/span&gt; not to be dynamically allocated, why do it when you can live without it?!&lt;/p&gt;

&lt;p&gt;Often novices make the mistake of allocating R objects from heap and then just deleting it. This will cause problems since they do not remember to call Close (Reset/ResetAndDestroy/whatever) needed to really release the resources allocated by the R object. delete does not do this and R destructors usually do not do this. You need to call Close explicitly.&lt;/p&gt;

&lt;p&gt;So just make your life easier, do not allocate R on heap but on stack, call Close (whatever) in the end and that&#039;s it. Furthermore, if your R object is actually a member variable of a C class, the memory used by the R object is actually on the heap already. So this does not save stack memory. The only place where stack is saved is when you use the R object inside a method temporarily. Finally, R classes do not often spend a lot of memory anyways, since the actual work with the actual data is done somewhere else, in a server usually.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;</description>
 <pubDate>Wed, 09 Apr 2008 08:12:42 +0200</pubDate>
 <dc:creator>Andreas</dc:creator>
 <guid isPermaLink="false">comment 45664 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: RPointerArray and CleanupStack</title>
 <link>http://www.newlc.com/forum/rpointerarray-and-cleanupstack#comment-45662</link>
 <description>&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;You are absolutely right,  there is no such restriction on RPointerArray that it has to be allocated on to the stack.&lt;br /&gt;
Now for cleanup purpose, CleanupStack provides 3 variants of PushL(). One  of the variant  takes TCleanupItem. For instance in your case the RPointerArray cannot simply be deleted(since we need to call Reset on it and delete all the pointers it contains), so you ve use this overloaded version of PushL (TCleanupItem aItem).This method allows us to define our own cleanup operation.The following code ll make you clear&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;void CleanupResetAndDestroy(TAny*&amp;nbsp; aItem)&lt;br /&gt;{&lt;br /&gt;RPointerArray&amp;lt;CMyClass&amp;gt; *pMyArray = (RPointerArray&amp;lt;CMyClass&amp;gt;*) aItem;&lt;br /&gt;pMyArray.ResetAndDestroy();&lt;br /&gt;pMyArray.Close();&lt;br /&gt;delete&amp;nbsp; pMyArray;&lt;br /&gt;//or u can use free if u dont ve any destructor&lt;br /&gt;}&lt;br /&gt;RPointerArray&amp;lt;CMyClass&amp;gt;*&amp;nbsp; CUtils::CreateRpointer(TInt Count)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RPointerArray&amp;lt;CMyClass&amp;gt; *pMyArray = new (ELeave)RPointerArray&amp;lt;CMyClass&amp;gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CleanupStack::PushL(TCleanupItem(CleanupResetAndDestroy(pMyArray ));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(TInt ct = 0; ct &amp;lt; Count; ct++)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CMyClass *myClass = CMyClass::NewL(ct);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (*pMyArray).AppendL(myClass);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return pMyArray;&lt;br /&gt;&amp;nbsp;&amp;nbsp; CleanupStack::Pop();&lt;br /&gt;}&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;
The CleanupResetAndDestroy operation is called when the subsequent call to CleanupStack::PopAndDestroy is made&lt;br /&gt;
Now Suppose the NewL of CMyClass leaves, CleanupResetAndDestroy is called and the cleanup is done.&lt;br /&gt;
This operation is more useful where u ve opened several resources and u need to cleanup.&lt;br /&gt;
I hope this is clear  &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, 09 Apr 2008 06:46:27 +0200</pubDate>
 <dc:creator>prajwal.r.m</dc:creator>
 <guid isPermaLink="false">comment 45662 at http://www.newlc.com</guid>
</item>
<item>
 <title>RPointerArray and CleanupStack</title>
 <link>http://www.newlc.com/forum/rpointerarray-and-cleanupstack</link>
 <description>&lt;p&gt;Hello All,&lt;/p&gt;

&lt;p&gt;I am trying to understand how the RPointerArray works&lt;/p&gt;

&lt;p&gt;I have written a piece of code as below and it is working perfectly fine.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/p&gt;

&lt;p&gt;RPointerArray&lt;CMyClass&gt;*  CUtils::CreateRpointer(TInt Count)&lt;br /&gt;
{&lt;br /&gt;
     RPointerArray&lt;CMyClass&gt; *pMyArray = new (ELeave)RPointerArray&lt;CMyClass&gt;();&lt;br /&gt;
     for(TInt ct = 0; ct &lt; Count; ct++)&lt;br /&gt;
     {&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://www.newlc.com/forum/rpointerarray-and-cleanupstack&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://www.newlc.com/forum/rpointerarray-and-cleanupstack#comments</comments>
 <category domain="http://www.newlc.com/forums/symbian-c">Symbian C++</category>
 <pubDate>Tue, 08 Apr 2008 15:44:34 +0200</pubDate>
 <dc:creator>mac123</dc:creator>
 <guid isPermaLink="false">20655 at http://www.newlc.com</guid>
</item>
</channel>
</rss>
