<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="http://blogs.forum.nokia.com/styles/rss.css" type="text/css"?>
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
>
 <channel>
  <title>Paul Todd&#039;s Forum Nokia Blog</title>
  <link>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog</link>
  <description>&lt;p&gt;Hi, I&#039;m Paul, but you can also call me Todd and I won&#039;t get upset.&lt;/p&gt;
</description>
  <pubDate>Mon, 23 Nov 2009 15:17:52 +0200</pubDate>
  <generator>http://www.lifetype.net</generator>
  <itunes:author>Forum Nokia</itunes:author>
  <itunes:category text="Technology">
    <itunes:category text="Tech News"/>
  </itunes:category>
  <itunes:image href="http://www.forum.nokia.com/piazza/blogs/imgs/forum_nokia_rss_logo.jpg"/>
    <item>
   <title>Variants and Symbian</title>
   <description>
    Been a while since I had a chance to post. What with the startup, summer holidays and work intruding.&lt;br /&gt;
The Champions day in Singapore was good fun, even got to meet Jukka and Anthony Pranata and&lt;br /&gt;
even got to do a day out around Singapore with Sammi and PushL.&lt;br /&gt;
&lt;br /&gt;
During the week, I had an interesting chat with Kevin Sharp about articles and blogs, so there &lt;br /&gt;
will be more source and articles on the Wiki and the blog will cover more reasons about why &lt;br /&gt;
I did something a certain way, rather than trying to cram it into a blog entry&lt;br /&gt;
&lt;br /&gt;
Recently I posted a new Wiki article which implements a &lt;a href=&quot;http://wiki.forum.nokia.com/index.php/Opaque_Data_Types_or_Variants&quot; target=&quot;undefined&quot;&gt;Variant class for Symbian.&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
A lot of the problems in Symbian revolve around the ownership of objects. &lt;br /&gt;
&lt;br /&gt;
In particular my implementation differed from Nokia&#039;s one in that I decided that if the user wanted to &lt;br /&gt;
add a string to the Variant then the Variant would own that string or data.&lt;br /&gt;
&lt;br /&gt;
This differs from the approach Nokia took with their variant class in the &lt;a href=&quot;http://wiki.forum.nokia.com/index.php/AIW_Generic_Parameters_API&quot; target=&quot;undefined&quot;&gt;AIW* API.&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
I decided amongst three possible types.&lt;br /&gt;
&lt;br /&gt;
Use a T class and push the ownership issues onto the person using the class. For example if you had an &lt;br /&gt;
HBufC then you were responsible for the resource management which is a bit of a cop out really and not &lt;br /&gt;
aligned with the standard Symbian programming idioms.&lt;br /&gt;
&lt;br /&gt;
Use a C class then the resource management issues are managable using Symbian Idioms, but its a pain to always&lt;br /&gt;
have to dereference a pointer.&lt;br /&gt;
&lt;br /&gt;
Finally I decided on an R class as the halfway point between an T class and a C class. The variant can own &lt;br /&gt;
resources, so if you have dynamic data, then you need to put the variant&amp;#160; onto the cleanup stack or call Release &lt;br /&gt;
when you have finished with it. This also means you can treat variants more like local variables, rather than &lt;br /&gt;
pointers.&lt;br /&gt;
&lt;br /&gt;
Internally the variant stores all the classes it supports as a union, much like the Windows implementation does,&lt;br /&gt;
though not as flexibly, primarily becuase Windows handles arrays so much better than Symbian. (Though Symbian &lt;br /&gt;
could make a much better job of it if the RArrayBase class were publically inherited!)&lt;br /&gt;
&lt;br /&gt;
What else do I want to do with RVariant?&lt;br /&gt;
I was thinking about adding TPtr support; the problem being when it comes to serializing the data, where you do not &lt;br /&gt;
know the destination, so if you are going across processes or writing to disk you invalidate the pointer.&lt;br /&gt;
&lt;br /&gt;
One thing is also adding in a TAny* pointer so arbitrary pointers could be put into a variant.&lt;br /&gt;
&lt;br /&gt;
With both of there the role of ownership really needs to be considered and for that reason I decided against putting&lt;br /&gt;
any specific Variant type for pointers, at least until I get the role of ownership sorted out in my head!&lt;br /&gt;
&lt;br /&gt;
One thing that might be useful is a change type function. In Windows there is a function called VariantChangeType that converts a variant from one type to another type where possible.&lt;br /&gt;
   </description>
   <link>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2007/07/18/variants-and-symbian</link>
   <comments>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2007/07/18/variants-and-symbian</comments>
   <guid>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2007/07/18/variants-and-symbian</guid>
      <dc:creator>Paul.Todd</dc:creator>
      
    <category>S60</category>
      
    <category>Series 80</category>
      
    <category>Symbian C++</category>
         <pubDate>Wed, 18 Jul 2007 23:08:35 +0300</pubDate>
   <itunes:author>Forum Nokia</itunes:author>
   <itunes:subtitle>Variants and Symbian</itunes:subtitle>
   <source url="http://blogs.forum.nokia.com/rss.php?blogId=1412&amp;profile=rss20">Paul Todd&#039;s Forum Nokia Blog</source>
     </item>
    <item>
   <title>Use and abuse of Symbian idioms</title>
   <description>
    I saw a very interesting snipped of code on the newsgroups the other day. It showed how people can so easily misuse Symbian programming idioms if they are not careful&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; RArray&amp;lt;TInt&amp;gt;* array = new (ELeave) RArray&amp;lt;TInt&amp;gt;;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; array-&amp;gt;Append(1);&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; array-&amp;gt;Append(2);&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; delete array;&lt;br /&gt;&lt;br /&gt;This is not the original class, the original class used another R class but the problem is still the same. &lt;br /&gt;To all intents and purposes this look like safe c++ code but the coder failed to realize that an RClose MUST be closed and cannot be deleted.&lt;br /&gt;&lt;br /&gt;I wonder how many other people have been bitten by this issue?
   </description>
   <link>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2007/04/02/use-and-abuse-of-symbian-idioms</link>
   <comments>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2007/04/02/use-and-abuse-of-symbian-idioms</comments>
   <guid>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2007/04/02/use-and-abuse-of-symbian-idioms</guid>
      <dc:creator>Paul.Todd</dc:creator>
      
    <category>S60</category>
      
    <category>Series 80</category>
      
    <category>Symbian C++</category>
         <pubDate>Mon, 02 Apr 2007 23:18:55 +0300</pubDate>
   <itunes:author>Forum Nokia</itunes:author>
   <itunes:subtitle>Use and abuse of Symbian idioms</itunes:subtitle>
   <source url="http://blogs.forum.nokia.com/rss.php?blogId=1412&amp;profile=rss20">Paul Todd&#039;s Forum Nokia Blog</source>
     </item>
    <item>
   <title>Some tips on C classes</title>
   <description>
    Here are some reminders about C type classes for a typical question I saw on NewLC&lt;br /&gt;&lt;br /&gt;Why does my C class not initialize the members to zero? Is this a bug?&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;1. Do not create C classes on the stack. &lt;/span&gt;&lt;br /&gt;This is the reason the member variables do not get set to zero. &lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;2. C classes allocate dynamic memory.&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;This will result in leaks if any of the methods following leave. &lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;3. C classes almost always do two phase construction.&lt;/span&gt;&lt;br /&gt;This is where the resources are allocated and at this point can leak if the object is not on the cleanup stack&lt;br /&gt; &lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;4. R classes allocate handles.&lt;/span&gt;&lt;br /&gt;- These handles may be leaked if any of the methods following the Open method leave.&lt;br /&gt;Be very careful if you open a handle and do not put it on the cleanup stack! &lt;br /&gt;People put returns in the middle of the function and forget to handle functions that leave.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;5. Programming standards in Symbian are paramount. &lt;/span&gt;&lt;br /&gt;-If the class allocates memory, derive it from CBase and put it on the cleanup stack. &lt;br /&gt;-If it is using handles, use an R class and put it on the cleanup stack&lt;br /&gt;See the &lt;a href=&quot;http://developer.symbian.com/wiki/pages/viewpage.action?pageId=530&quot;&gt;Symbian Wiki&lt;/a&gt; for more information on standards&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;6. Follow Scott Meyers advice and make your constructors and ConstructL class private.&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;-So that the class cannot be inadvertantly created on the stack. &lt;br /&gt;-Make you copy constructor and assignment operator private and unimplemented so you get compile errors if you accidentally use them.&lt;br /&gt;-Always use NewLC or NewLC to force people to use the proper constructor&lt;br /&gt;&lt;a href=&quot;http://www.amazon.com/Effective-C++-Specific-Improve-Programs/dp/0201924889&quot;&gt;Effective C++: 50 Specific Ways to Improve your Programs and Design&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;7. Put the address of the item you expect to be at the top of the stack in the argument for PopAndDestroy&lt;/span&gt;&lt;br /&gt;There are overloads on PopAndDestroy that allow you to provide a pointer for the item you expect to be on the top of the stack after popping and destroying items.&lt;br /&gt;You will get a panic if this item is not at the top of the stack after the items have been popped.&lt;br /&gt;
   </description>
   <link>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2007/02/25/some-tips-on-c-classes</link>
   <comments>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2007/02/25/some-tips-on-c-classes</comments>
   <guid>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2007/02/25/some-tips-on-c-classes</guid>
      <dc:creator>Paul.Todd</dc:creator>
      
    <category>Series 80</category>
      
    <category>Symbian C++</category>
         <pubDate>Sun, 25 Feb 2007 21:51:51 +0200</pubDate>
   <itunes:author>Forum Nokia</itunes:author>
   <itunes:subtitle>Some tips on C classes</itunes:subtitle>
   <source url="http://blogs.forum.nokia.com/rss.php?blogId=1412&amp;profile=rss20">Paul Todd&#039;s Forum Nokia Blog</source>
     </item>
    <item>
   <title>CStack and a little problem</title>
   <description>
    Someone emailed me a while back on how to use CStack. A quick search of the devkit with Copernic search showed no examples so I decided to post some code on how to use it.&lt;br /&gt;&lt;br /&gt;The Symbian implemenent of a stack is a simple array where items are appended to the end of the array. This is both simple, elegant and unobtrusive.&lt;br /&gt;&lt;br /&gt;First decide if the stack is to hold pointer or structures. &lt;br /&gt;If the array is to hold pointers, then does the array own the pointer? Normally the answer is yes.&lt;br /&gt;&lt;br /&gt;Lets say we want to create a stack of strings, then these strings would be implemented as HBufC&#039;s &lt;br /&gt;so to make life easier, when a string is on the stack, the stack owns the the string.&lt;br /&gt;&lt;br /&gt;So the stack can now be declared as (note the stack owns the data it contains!):&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;CStack&amp;lt;HBufC, ETrue&amp;gt;* myStack = new (ELeave) CStack&amp;lt;HBufC, ETrue&amp;gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;As we have declared it on the heap, we need to remember to push it onto the cleanup stack&lt;br /&gt;so that if there is a leave it get cleans up nicely.&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;CleanupStack::PushL(myStack);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To add an item onto the stack is simple&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;_LIT(KFirstItemOntoTheStack, &amp;quot;My First Item&amp;quot;);&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;myStack-&amp;gt;PushL(KFirstItemOntoTheStack().AllocL());&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;br /&gt;Here we create a copy of KFirstItemOntoTheStack and then put it onto the stack, note&lt;br /&gt;that at all times it is leave safe and nothing leaks if for example PushL fails.&lt;br /&gt;This is because when we created the stack class we told it that it owns all the memory&lt;br /&gt;&lt;br /&gt;Of course now we can get the top item, which returns an HBufC*&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;HBufC* top = myStack-&amp;gt;Head();&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;br /&gt;and check to see if the stack is empty&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;if (myStack-&amp;gt;IsEmpty())&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // do something&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;br /&gt;There are also the usual Pop to remove the top item (but not delete it!) and Head to get the top item,&lt;br /&gt;which for some reason is not declared as Top, like my CS 101 class taught, go figure?&lt;br /&gt;&lt;br /&gt;Now we have finished with the stack, we can delete it, this also deletes all the items&lt;br /&gt;owned by the cleanup stack.&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;CleanupStack::PopAndDestroy(myStack);&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;br /&gt;This is a pretty good implementation and to be be quite honest the only thing I would really like to see&lt;br /&gt;would be for it to be an R class derived from RPointerArray.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Now for a little quiz:&lt;/span&gt;&lt;br style=&quot;font-style: italic;&quot; /&gt;What is wrong with this code?&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;struct TMyVersionStruct&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;#160;&amp;#160;&amp;#160; TUint32&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; iVersion;&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;#160;&amp;#160;&amp;#160; TUint32&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; iItem1;&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;#160;&amp;#160;&amp;#160; TUint32&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; iItem2;&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;#160;&amp;#160;&amp;#160; TUint32&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; iItem3;&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;#160;&amp;#160;&amp;#160; TUint32&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; iItem4;&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;#160;&amp;#160;&amp;#160; TUint32&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; iItem5;&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;#160;&amp;#160;&amp;#160; TUint32&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; iItem6;&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;};&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;LOCAL_C void TestCrash()&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;#160;&amp;#160;&amp;#160; // The production code reads a blob from disk and it looks correct&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; // in the debugger but it itermittantly crashes, &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; // here however we simulate what the read from disk as the problem &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; // is not in the reading...&lt;br /&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;#160;&amp;#160;&amp;#160; HBufC8* item = HBufC8::NewL(sizeof(TMyVersionStruct));&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;#160;&amp;#160;&amp;#160; item-&amp;gt;Des().SetLength(item-&amp;gt;Des().MaxLength());&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;#160;&amp;#160;&amp;#160; TMyVersionStruct version;&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;#160;&amp;#160;&amp;#160; TPtr8 ver((TUint8*)&amp;amp;version, sizeof(version));&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;#160;&amp;#160;&amp;#160; ver = *item;&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;#160;&amp;#160;&amp;#160; delete item;&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160; // do something with version&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/span&gt;&lt;br style=&quot;font-weight: bold;&quot; /&gt;&lt;br /&gt;Its an interesting if very subtle problem that seems to come up when memory is very fragmented and is &lt;br /&gt;fiendishly annoying.&lt;br /&gt;&lt;br /&gt;Answers next week.....
   </description>
   <link>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2006/11/14/cstack-and-a-little-problem</link>
   <comments>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2006/11/14/cstack-and-a-little-problem</comments>
   <guid>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2006/11/14/cstack-and-a-little-problem</guid>
      <dc:creator>Paul.Todd</dc:creator>
      
    <category>S60</category>
      
    <category>Series 80</category>
      
    <category>Symbian C++</category>
         <pubDate>Tue, 14 Nov 2006 22:35:08 +0200</pubDate>
   <itunes:author>Forum Nokia</itunes:author>
   <itunes:subtitle>CStack and a little problem</itunes:subtitle>
   <source url="http://blogs.forum.nokia.com/rss.php?blogId=1412&amp;profile=rss20">Paul Todd&#039;s Forum Nokia Blog</source>
     </item>
    <item>
   <title>Shutting down Servers and Threads Part 2</title>
   <description>
    In the first part we covered how to correctly and cleanly shutdown a process.&lt;br /&gt;&lt;br /&gt;Now we are going to cover how to shutdown a thread.&lt;br /&gt;&lt;br /&gt;Typically people start threads to do some form of processing but often fail to plan how to shutdown a thread.&lt;br /&gt;I often heard the old saying &amp;quot;Fail to Plan then plan to fail&amp;quot;. It is essential to decide early on what conditions are necessary for the thread to stop.&lt;br /&gt;&lt;br /&gt;By terminating threads all sorts of issues can be introduced or can can occur depending on when the thread is killed so it really makes sense to plan how to end the threads aside from using terminate or kill.&lt;br /&gt;&lt;br /&gt;There are a number of ways to stop a thread and we are going to cover the most important ones here&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Watching for a thread to die&lt;/span&gt;&lt;br /&gt;In Symbian the easiest way to watch for the thread dying is to use the RThread::Logon method.&lt;br /&gt;&lt;br /&gt;You can use it as follows:&lt;br /&gt;RThread thread;&lt;br /&gt;thread.Open(myThreadId);&lt;br /&gt;TRequestStatus watcher;&lt;br /&gt;thread.Logon(watcher);&lt;br /&gt;&lt;br /&gt;// start your thread shutdown here&lt;br /&gt;// The below will block until the thread dies&lt;br /&gt;// so make sure you shutdown quickly, otherwise you will&lt;br /&gt;// need to use a wait dialog or something similar&lt;br /&gt;User::WaitForRequest(watcher);&lt;br /&gt;&lt;br /&gt;Note that until the thread dies, the thread that is executing the logon/WaitForRequest will be blocked, though you can encapsulate the logon inside an active object. In practice the time from the point where you request the thread to when it is shutdown is sub-second so its normally not worth the hassle.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Using a TRequestStatus to stop a thread&lt;/span&gt;&lt;br /&gt;This is normally the &amp;quot;Symbian&amp;quot; preferred method. &lt;br /&gt;&lt;br /&gt;Here you pass a pointer an TRequestStatus the thread and when you want to shut down the thread you just complete the TRequeststatus and wait for the thread to complete. Note that the TRequestStatus is &amp;quot;used&amp;quot; by the thread being shutdown and not be the calling thread. It looks intuitively wrong but works.&lt;br /&gt;&lt;br /&gt;TRequestStatus* killer = NULL;&lt;br /&gt;mythread.Create(_L(&amp;quot;Thread&amp;quot;), MyThreadFunction, 1000,1000,2000, killer);&lt;br /&gt;....&lt;br /&gt;.... we now want to stop the thread&lt;br /&gt;TRequestStatus waiter;&lt;br /&gt;myThread.Logon(waiter); // watch the thread&lt;br /&gt;User::RequestComplete(killer, KErrNone);&amp;#160; // tell the thread to stop&lt;br /&gt;User::WaitForRequest(waiter); // when it closes the wait will end&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;LOCAL_C void MyThreadFunction(TAny* aAny)&lt;br /&gt;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160; // setup stuff like active scheduler etc.&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160; TRequestStatus threadstop = KRequestPending;&lt;br /&gt;&amp;#160;&amp;#160; TRequestStatus* sink = REINTERPRET_CAST(TRequestStatus*,aAny);&lt;br /&gt;&amp;#160;&amp;#160; sink = &amp;amp;threadstop;&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160; // do something e.g.&lt;br /&gt;&amp;#160;&amp;#160; TRequestStatus event;&lt;br /&gt;&amp;#160;&amp;#160; wsSession.EventReady(&amp;amp;event);&lt;br /&gt;&amp;#160;&amp;#160; // Note WaitForRequest allows two AO&#039;s!&lt;br /&gt;&amp;#160;&amp;#160; User::WaitForRequest(event, threadstop);&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160; if (threadstop != KRequestPending)&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // this is called when the stop TRS was&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // signalled by the main app&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; //&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // do what ever you need to stop the thread&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // e.g. shut handles, delete object etc.&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160; // event was signalled so do some more processing&lt;br /&gt;&amp;#160;&amp;#160; // this was not the thread stop TRS so we can still run&lt;br /&gt;&amp;#160;&amp;#160; // as we have not been requested to shut down&lt;br /&gt;&amp;#160;&amp;#160; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Using a global variable&lt;/span&gt;&lt;br /&gt;In your main application you can create a global variable, say static TInt32 gShutdownFlag = 0. Of course it need to be static, you could pass a pointer across just as easily.&lt;br /&gt;&lt;br /&gt;You can then set this from your main application and in your thread loop you can check to see if this flag is correctly. this is particularly suited to games as these generally do not use Active Objects heavily.&lt;br /&gt;&lt;br /&gt;A source of concern might be that reading and writing data across threads is unsafe. Generally speaking read and writes are safe provided they are 32 bits wide. However in OS 9.x Symbian have introduced a new API in the User module, called SafeInc and SafeDec which guarantee that this is atomic.&lt;br /&gt;&lt;br /&gt;Another method which I have&#039;nt used is the Publish and Subscribe API. This API allows different processes to work with a common system wide global variable.
   </description>
   <link>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2006/09/19/shutting-down-servers-and-threads-part-2</link>
   <comments>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2006/09/19/shutting-down-servers-and-threads-part-2</comments>
   <guid>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2006/09/19/shutting-down-servers-and-threads-part-2</guid>
      <dc:creator>Paul.Todd</dc:creator>
      
    <category>S60</category>
      
    <category>Series 80</category>
      
    <category>Symbian C++</category>
         <pubDate>Tue, 19 Sep 2006 17:43:30 +0300</pubDate>
   <itunes:author>Forum Nokia</itunes:author>
   <itunes:subtitle>Shutting down Servers and Threads Part 2</itunes:subtitle>
   <source url="http://blogs.forum.nokia.com/rss.php?blogId=1412&amp;profile=rss20">Paul Todd&#039;s Forum Nokia Blog</source>
     </item>
    <item>
   <title>Microsoft CE Emulator Goes Open Source</title>
   <description>
    Microsoft are definalty leading the way with their Windows CE Emulation (or to be correct Simulation).&lt;br /&gt;&lt;br /&gt;Features include&lt;br /&gt;
&lt;ul&gt;&lt;span&gt;
    &lt;li&gt; CPU emulator that executes the ARM instruction set by JIT-compiling to x86 &lt;/li&gt;
    &lt;li&gt; An MMU emulator to support virtual memory and page protection &lt;/li&gt;
    &lt;li&gt; A motherboard emulator that contains emulated RAM and NOR flash memory &lt;/li&gt;
    &lt;li&gt; A collection of peripheral devices attached to the motherboard: serial ports, LCD controller, touchscreen, keyboard, interrupt controller, programmable timers, real-time-clock, network cards, audio, etc. &lt;/li&gt;
    &lt;li&gt; A &amp;#8220;DMA&amp;#8221; interface which allows a Win32 application running outside the emulator to communicate with a WinCE application running inside the emulator, using a simple socket-like programming model.&lt;/li&gt;
    &lt;/span&gt;&lt;/ul&gt;
    Even though this is in effect a techview release of the emulator, it would be really nice to see Symbian provide the same level of emulation that Microsoft do, especially regarding the native arm support which provides full ARM emulation including alignment faults, which are the bane of every project that has one hacker on it :)&lt;br /&gt;&lt;br /&gt;Come on Symbian, give us a better emulator! If Microsoft can do it and make it open source, this definitely raises the bar for you guys!&lt;br /&gt;&lt;br /&gt;p.s FileMan is stuck in Symbian signed :(
   </description>
   <link>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2006/07/20/microsoft-ce-emulator-goes-open-source</link>
   <comments>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2006/07/20/microsoft-ce-emulator-goes-open-source</comments>
   <guid>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2006/07/20/microsoft-ce-emulator-goes-open-source</guid>
      <dc:creator>Paul.Todd</dc:creator>
      
    <category>S60</category>
      
    <category>Series 80</category>
      
    <category>Symbian C++</category>
         <pubDate>Thu, 20 Jul 2006 11:28:20 +0300</pubDate>
   <itunes:author>Forum Nokia</itunes:author>
   <itunes:subtitle>Microsoft CE Emulator Goes Open Source</itunes:subtitle>
   <source url="http://blogs.forum.nokia.com/rss.php?blogId=1412&amp;profile=rss20">Paul Todd&#039;s Forum Nokia Blog</source>
     </item>
    <item>
   <title>SyExpat Port to OS 9.x</title>
   <description>
    I was going to post this on Sunday but with the uncharacteristically good British Summer and England playing Sweden&lt;br /&gt;in football, this slipped over to Wednesday.&lt;br /&gt;&lt;br /&gt;Originally I thought that porting SyExpat to OS 9.x would involve a large number of changes.&lt;br /&gt;In the end this turned out to be not the case.&lt;br /&gt;&lt;br /&gt;The simplest fix was to xmlparse.c. It seems that the expat guys mixed up the return code enum and the error&lt;br /&gt;code enum, so changing it is all that is needed for the main expat source code.&lt;br /&gt;&lt;br /&gt;A slightly tricker problem was the with GCCE. It seems that it likes to define XMLCALL to something. GCCE seems to think it supports Microsoft extensions but it only does it in some cases.I think it was _MSC_EXTENSIONS, so in order to fix this we need to make sure that expat_config.h is defined before expat.h is included in the source files. This will then define XMLCALL and so stop expat_external.h defining it to the default.&lt;br /&gt;&lt;br /&gt;The only change then resolves to just make the SyExpat.cpp file include the expat_config file before expat.h &lt;br /&gt;as this sets up a&amp;#160; number of defines that specify how the functions are to be exported and so this sorts out the export declarations not being handles correctly.&lt;br /&gt;&lt;br /&gt;Hence we just define XML call as blank and this fixes the compiler issues. See expat_config.h for more&lt;br /&gt;information.&lt;br /&gt;&lt;br /&gt;This is now sufficient to be able to build SyExpat for OS 9.x and still retain backward compatibility.&lt;br /&gt;&lt;br /&gt;Unfortunately I have run into rather a nasty issue with Carbide.vs and the standard C library.&lt;br /&gt;The whole sorry tale is here - &lt;a href=&quot;http://discussion.forum.nokia.com/forum/showthread.php?t=75575&quot;&gt;http://discussion.forum.nokia.com/forum/showthread.php?t=75575&lt;/a&gt; so for the&lt;br /&gt;moment it seems there are some serious OS9 issues to fix first, even in the maintentance release.&lt;br /&gt;&lt;br /&gt;Thanks to Harri Salminen for his fix for name space parsing which has now bee incorporated as well.&lt;br /&gt;&lt;br /&gt;If anyone has any specific problem areas in Symbian they would like covered please email me and I will try to knock something up to show it is supposed to work.&lt;br /&gt;&lt;br /&gt;Next week I will look at how to use MobInfo (and CTelephony) as a number of people seem to have a problem understanding how to use active objects with these libraries.&lt;br /&gt;&lt;br /&gt;Addendum:&lt;br /&gt;I have just found out I cannot attach files to blog entries so I will put the actual revised code up on my website.
   </description>
   <link>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2006/06/21/syexpat-port-to-os-9.x</link>
   <comments>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2006/06/21/syexpat-port-to-os-9.x</comments>
   <guid>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2006/06/21/syexpat-port-to-os-9.x</guid>
      <dc:creator>Paul.Todd</dc:creator>
      
    <category>S60</category>
      
    <category>Series 80</category>
      
    <category>Symbian C++</category>
         <pubDate>Wed, 21 Jun 2006 21:12:44 +0300</pubDate>
   <itunes:author>Forum Nokia</itunes:author>
   <itunes:subtitle>SyExpat Port to OS 9.x</itunes:subtitle>
   <source url="http://blogs.forum.nokia.com/rss.php?blogId=1412&amp;profile=rss20">Paul Todd&#039;s Forum Nokia Blog</source>
     </item>
    <item>
   <title>RArray and Resource Mangement</title>
   <description>
    &lt;font size=&quot;2&quot;&gt;
&lt;p&gt;&amp;#160;&lt;/p&gt;
&lt;p&gt;If you are not using RArray, you should be! &lt;br /&gt;It offers a substantial performance improvement over the CArray.. implementations for almost all the cases I can think of.&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;It is fast - RArray is coded in ARM assembly in release versions of the code.&lt;/li&gt;
    &lt;li&gt;It does not use asserts internally and also does not leave, it just returns error codes, so the use of trap statements in runtime significant areas of the code can be minimized or reduced.&lt;/li&gt;
    &lt;li&gt;It is lightweight&lt;/li&gt;
    &lt;li&gt;It is a wrapper over a more complex implementation of a generic array.&lt;/li&gt;
    &lt;li&gt;There are templated version of TInt and TUint built into EUSER so it does not bloat your executable.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Most of RArray is fairly simple to understand and works the way any generic array implementation works.&lt;/p&gt;
&lt;p&gt;The biggest problem I do have with RArray is that the search and insert functions do not allow a variable to be passed to them so you are required to use a global or some other hack to get a state variable over into the comparison function.&lt;/p&gt;
&lt;p&gt;The areas I am going look at are how RArray manages resources and how RArray can be applied effectively used to improve performance.&lt;/p&gt;
&lt;p&gt;Before we can continue there are some questions that need to be answered:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How does RArray allocates memory?&lt;br /&gt;&lt;/strong&gt;If you play around with RArray you will soon find out that it allocates memory via the User::Alloc functions and these allocations are always a multiple of 4 bytes.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What RArray Constructors are there?&lt;br /&gt;&lt;/strong&gt;There is a default constructor, a constructor that specifies by how much the array will be expanded when it runs out of spare slots, and most importantly a constructor that maps onto a memory locations- but more of that later.&lt;/p&gt;
&lt;p&gt;What is not present is a copy constructor, so what will happen then is that the C++ compiler will create a default constructor that is a bitwise copy of the item it is being copied from.&lt;/p&gt;
&lt;p&gt;By default RArray does not have any items, however if one item is added, it preallocates by default 8 items, well okay KGranularity items so it can avoid memory fragmentation when adding items by avoiding a reallocate and copy each time an item is added.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Resource Management:&lt;br /&gt;&lt;/strong&gt;For the purposes of the example we will create a structure called TVector which has two integers in it. &lt;br /&gt;&lt;strong&gt;THIS STRUCTURE IS A MUTIPLE OF 4 BYTES WHICH IS MANDATORY FOR RARRAY ELEMENTS!&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;struct TVector&lt;br /&gt;{&lt;br /&gt;&amp;#160; TInt iSpeed;&lt;br /&gt;&amp;#160; TInt iDirection;&lt;br /&gt;};&lt;br /&gt;typedef RArray&amp;lt;TVector&amp;gt; RVectorArray; // Note that we keep the R prefix on our typedef&lt;/p&gt;
&lt;p&gt;(1) static const TVector data[] = { {1,1}, {2,2}, {3,3} };&lt;br /&gt;(2) const RVectorArray array(sizeof(TVector), CONST_CAST(TVector*,&amp;amp;data[0]), sizeof(data) / sizeof(data[0]));&lt;br /&gt;(3) RVectorArray array1;&lt;br /&gt;(4) array1 = array;&lt;br /&gt;(5) TInt count = array.Count();&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Each of the lines is numbered and documented as follows:&lt;br /&gt;&lt;/em&gt;(1) we create a static const memory block. This could also be a block of memory from somewhere else such as a scanline or bitmap row.&lt;br /&gt;(2) We now create an RArray that maps that memory into the RArray, note that the array is const so we can&#039;t expand it by accident. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;It is important to read the documentation on this as it is very clear that this constructor does not allocate any memory nor take ownership of the memory, it just provides a mapping for developers to use the RArray with blocks of memory that needs to be manipulated.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;(3) We now create a default RArray which has not memory allocated and it does not have any elements.&lt;/p&gt;
&lt;p&gt;(4) Finally we create a clone of the array. It is vital to note that the compiler has underneath generated a default copy constructor and created a bitwise clone of data into array.&lt;/p&gt;
&lt;p&gt;(5) Finally get the number of items in array after we have cloned it. What is the value of count? &lt;br /&gt;Answer: See below&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;IMPORTANT NOTES:&lt;br /&gt;&lt;/strong&gt;(2) This just creates a mapping of the memory structure into the RArray is does not force the RArray to allocate any memory, hence there is nothing that needs to be put onto the cleanup stack. This is a very important point that a lot of people get wrong.&lt;br /&gt;(4) This creates a clone of the array but ownership of the items in the data array is not taken&lt;br /&gt;(5) Since array is a clone of data, count is 3&lt;br /&gt;(6) When the function goes out of scope the arrays are destroyed, but we do not call reset. This is very important, because the arrays do not own any memory they MUST NOT be freed, so calling Reset is a big no-no! Likewise putting it on the cleanup stack is also a big mistake and will cause crashes.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Resource Management Part 2:&lt;br /&gt;&lt;/strong&gt;As I mentioned earlier, the underyling memory allocator for RArray is User::Alloc, so providing we allocate memory via this mechanism, we can move memory blobs from our structure into an RArray and then use the RArray.&lt;/p&gt;
&lt;p&gt;(1) TVector* data2 = REINTERPRET_CAST(TVector*, User::AllocL(sizeof(data))); // actually sizeof(data) / (sizeof(data) / sizeof(data[0]))&lt;br /&gt;(2) Mem::Copy(data2, data, sizeof(data));&lt;br /&gt;(3) RVectorArray array2(sizeof(TVector), data2, sizeof(data) / (sizeof(data) / sizeof(data[0])));&lt;br /&gt;(4) CleanupClosePushL(array2);&lt;br /&gt;(5) const TVector element = {4,4};&lt;br /&gt;(6) array2.Append(element);&lt;br /&gt;(7) count = array2.Count();&lt;br /&gt;(8) CleanupStack::PopAndDestroy(&amp;amp;array2);&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Each of the lines is nummered and documented as follows:&lt;br /&gt;&lt;/em&gt;(1) We allocate a block of memory using User::Alloc that is size of the &#039;data&#039; structure (3 * sizeof(TVector))&lt;br /&gt;This data is not put onto the cleanup stack, though of course we could put it onto the cleanup stack here and then remove it from the cleanup stack on line (4) and add the RArray back to the cleanup stack.&lt;br /&gt;(2) We now copy the data from the const memory structure to our newly allocated memory blob&lt;br /&gt;(3) We now create an RArray that maps the memory we just allocated to the internals of an RArray.&lt;br /&gt;(4) Because we allocated the memory somewhere else, I decided that the RArray should now take ownership of the array, so that if any of the following lines should leave the memory will get correctly cleaned up by the RArray.&lt;br /&gt;(5) we declare a new element&lt;br /&gt;(6) This element is now added to our array that owns the memory. Where the array is full, the array will be expanded to cater for the new element, which may result in a memory reallocation, hence BE VERY CAREFUL where ownership of memory blocks is made.&lt;br /&gt;(7) What should count now report? Answer: 4&lt;br /&gt;(8) As we transfered ownship of the memory block to the array2 RArray, the cleanup stack may now delete it. If we did not put it onto the cleanup stack, we can just call Reset which has the same effect.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;IMPORTANT NOTES:&lt;br /&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;(4) Is very important as you want to move ownership of the memory block to the RArray as soon as possible, especially if you want to add or remove items from the RArray.&lt;br /&gt;(6) We should really check the return value from the append as it could have returned a negative value which would indicate that the item failed to expand. I have seen a number of cases where the error code is never checked and so unexpected things start happening.&lt;br /&gt;(8) We do not neccessarily need to put the array2 as a parmeter to the PopAndDestroy but it provides an additional check that the item at the top of the stack is the item we expected it to be.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Some other things about RArray and RPointerArray&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;This is an advanced example of how to use resource management and RArray. Its not for beginners.&lt;/li&gt;
    &lt;li&gt;In real life I have used to read a block of integers (5000) from disk as a TPtrC8&amp;#160;and then cast it and move it to the RArray where the RArray takes ownership of the data. Which knocked about 10 seconds off the load time.&lt;/li&gt;
    &lt;li&gt;The arrays only take items that are 4 bytes or a multiple of 4 bytes, so if your object is say 9 bytes then the RArray will internally allocate 12 bytes for each item, hence take care when creating structures. Likewise, if your structure has different size items in it, check at compile time that the size is what you expect it to be. I have encountered situations where the sizeof has reported a different to what I had expected becuase of alignment issues in structure fields. &lt;/li&gt;
    &lt;li&gt;To get the address of the block of memory allocated to the RArray, take the address of element zero. &lt;br /&gt;i.e. TVector* ptr = &amp;amp;(array[0]); &lt;/li&gt;
    &lt;li&gt;RPointerArray does not have an implementation that destroys all the pointer objects. Normally you would do this via ResetAndDestroy. For some reason Symbian decided to put the implementation of this in mmfcontrollerpluginresolver.h. The function is called &lt;strong&gt;CleanupResetAndDestroyPushL&lt;/strong&gt; &lt;/li&gt;
    &lt;li&gt;One source of problems with RArray is when appending a large number of items to the array in one go. &lt;br /&gt;For example lets say:&lt;br /&gt;(1) RArray&amp;lt;TInt&amp;gt; array;&lt;br /&gt;(2) for (TInt i=0; i &amp;lt; 1000; i++)&lt;br /&gt;(3)&amp;#160;&amp;#160;&amp;#160; array.Append(i);&lt;br /&gt;&lt;br /&gt;Each time (3) is called when the array hits capacity, it will need to be expanded by its default granularity (8) which means that there will be a large number (124 reallocations) during this example.&lt;br /&gt;In OS 9.x Symbian has added a Reserve function which preallocates a specified number of items in the RArray so that when adding items, the array does not need to be expanded which reduces memory fragmentation.&lt;br /&gt;To simulate this in OS7 and OS8, we can reuse the tech above to allocate and transfer ownership.&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;(1) RArray&amp;lt;TVector&amp;gt; temp(sizeof(TVector), REINTERPRET_CAST(TVector*, User::AllocL(1000 * sizeof(TVector))), 1000);&lt;br /&gt;(2) for (TInt i= 1000-1; i &amp;gt;= 0; i--)&lt;br /&gt;(3)&amp;#160;&amp;#160;&amp;#160; temp.Remove(i);&lt;br /&gt;(4) RArray&amp;lt;TVector&amp;gt; array3 = temp;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Important Notes&lt;br /&gt;&lt;/strong&gt;(1) We allocate 1000 items and put it into the RArray.&lt;br /&gt;(2,3) We then remove the items starting from the back which prevents horrific memory copying.&lt;br /&gt;(4) Finally assign the new array to the existing array. Note that if the existing array (array3) already has items then you will need to call Reset on it before assigning the items, otherwise the memory in the array will be orphaned and you will get a memory leak. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;In Conclusion:&lt;br /&gt;&lt;/strong&gt;I hope this has provided an example of how to use resources in RArray where speed is critical. Needless to say, make sure that if you use this technique you keep it localized to one function so that the maintainer can know exactly what you are doing as these techniques need to be used to extreme care and only where there is time critical code.&lt;/p&gt;
&lt;p&gt;Next week I want to discuss how I ported SyExpat to OS 9 which I have been promising to deliver for ages now. Its coded, I just hav&#039;nt had a chance to document what I changed and why.&lt;/p&gt;
&lt;p&gt;I only just posted a comment about multidimensional RArrays so I might publish some additional notes about these this week as well.&lt;/p&gt;
&lt;/font&gt;
   </description>
   <link>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2006/06/12/rarray-and-resource-mangement</link>
   <comments>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2006/06/12/rarray-and-resource-mangement</comments>
   <guid>http://blogs.forum.nokia.com/blog/paul-todds-forum-nokia-blog/2006/06/12/rarray-and-resource-mangement</guid>
      <dc:creator>Paul.Todd</dc:creator>
      
    <category>S60</category>
      
    <category>Series 80</category>
      
    <category>Symbian C++</category>
         <pubDate>Mon, 12 Jun 2006 00:37:11 +0300</pubDate>
   <itunes:author>Forum Nokia</itunes:author>
   <itunes:subtitle>RArray and Resource Mangement</itunes:subtitle>
   <source url="http://blogs.forum.nokia.com/rss.php?blogId=1412&amp;profile=rss20">Paul Todd&#039;s Forum Nokia Blog</source>
     </item>
   </channel>
</rss>