<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss'><id>tag:blogger.com,1999:blog-12650648</id><updated>2009-10-16T15:47:47.933-07:00</updated><title type='text'>Descriptors FAQ</title><subtitle type='html'>"Everything about Symbian OS descriptors"</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default?start-index=26&amp;max-results=25'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>43</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-12650648.post-116449011457651647</id><published>2006-11-25T13:26:00.000-08:00</published><updated>2006-11-25T13:30:40.126-08:00</updated><title type='text'>36. How do I use RBuf to read from a file?</title><content type='html'>This was posted by Simo as a comment &lt;a href="http://descriptors.blogspot.com/2005/06/33-can-you-give-example-of-how-to-use.html"&gt;here&lt;/a&gt;:&lt;br /&gt;&lt;br /&gt;RBuf is also the best choice when reading strings from file. Using RBuf instead of HBufC requires less code. Also, error handling becomes more simpler.&lt;br /&gt;&lt;br /&gt;Here is simple example how to read from RReadStream:&lt;br /&gt;&lt;br /&gt;in .h: RBuf iSomeSetting;&lt;br /&gt;in .cpp: iSomeSetting.CreateL( stream, KMaxTInt );&lt;br /&gt;&lt;br /&gt;the HBufC would be:&lt;br /&gt;in .h: HBufC* iSomeSetting;&lt;br /&gt;in .cpp: iSomeSetting = HBufC::NewL( stream, KMaxTInt );&lt;br /&gt;TPtr tmp( iSomeSetting-&gt;Des() );&lt;br /&gt;stream &gt;&gt; tmp;&lt;br /&gt;&lt;br /&gt;Error handling is also easier because there are no NULL pointer checks required for RBuf.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-116449011457651647?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/116449011457651647/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=116449011457651647' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/116449011457651647'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/116449011457651647'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2006/11/36-how-do-i-use-rbuf-to-read-from-file.html' title='36. How do I use RBuf to read from a file?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-114824629456262238</id><published>2006-05-21T14:16:00.000-07:00</published><updated>2006-05-22T09:52:13.326-07:00</updated><title type='text'>References to other descriptors resources</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;General Symbian Resources&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Symbian Developer Library on the Symbian site (&lt;span style="font-size:85%;"&gt;&lt;a href="http://www.symbian.com/developer/techlib/index.asp"&gt;www.symbian.com/developer/techlib/index.asp&lt;/a&gt;&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;Version 9.1: &lt;a href="http://www.symbian.com/developer/techlib/v9.1docs/doc_source/index.html"&gt;www.symbian.com/developer/techlib/v9.1docs/doc_source/index.html&lt;/a&gt;&lt;br /&gt;Version 8.1a: &lt;a href="http://www.symbian.com/developer/techlib/v8.1adocs/doc_source/index.html"&gt;www.symbian.com/developer/techlib/v8.1adocs/doc_source/index.html&lt;/a&gt;&lt;br /&gt;Version 7.0s: &lt;a href="http://www.symbian.com/developer/techlib/v70sdocs/doc_source/index.html"&gt;www.symbian.com/developer/techlib/v70sdocs/doc_source/index.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Developer Communities&lt;/span&gt;&lt;br /&gt;Symbian: &lt;a href="http://www.symbian.com/developer/"&gt;www.symbian.com/developer/&lt;/a&gt;&lt;br /&gt;Forum Nokia: &lt;a href="http://www.forum.nokia.com"&gt;www.forum.nokia.com&lt;/a&gt;&lt;br /&gt;UIQ Developer Community: &lt;a href="http://developer.uiq.com/"&gt;developer.uiq.com/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;My book: "Symbian OS Explained" &lt;a href="http://www.symbian.com/developer/books/sose/sose_info.html"&gt;www.symbian.com/developer/books/sose/sose_info.html&lt;/a&gt; and personal web site &lt;a href="http://www.WhoShavesTheBarber.com"&gt;www.WhoShavesTheBarber.com&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Other Symbian Press titles: &lt;a href="http://www.symbian.com/developer/books/index.html"&gt;www.symbian.com/developer/books/index.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Symbian Developer FAQ and Tech Tips site: &lt;a href="http://www.symbian.com/developer/faq/index.html"&gt;www.symbian.com/developer/faq/index.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;References&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Reference [1]&lt;/span&gt; Descriptors overview from the Symbian Developer Library&lt;br /&gt;&lt;a href="http://www.symbian.com/developer/techlib/v9.1docs/doc_source/guide/Base-subsystem-guide/N10086/BuffersAndStrings/DescriptorsOverview.guide.html#BuffersAndStringsOverview%2eDescriptorsOverview%2emain"&gt;www.symbian.com/developer/techlib/v9.1docs/doc_source/guide/Base-subsystem-guide/N10086/BuffersAndStrings/DescriptorsOverview.guide.html#BuffersAndStringsOverview%2eDescriptorsOverview%2emain&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Reference [2]&lt;/span&gt; &lt;span style="font-family:courier new;"&gt;USER&lt;/span&gt; panic category in the Symbian Developer Library&lt;br /&gt;&lt;a href="http://www.symbian.com/developer/techlib/v9.1docs/doc_source/reference/N10352/UserPanics.html#Panics%2euser"&gt;www.symbian.com/developer/techlib/v9.1docs/doc_source/reference/N10352/UserPanics.html#Panics%2euser&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Reference [3]&lt;/span&gt; Format String Syntax in the Symbian Developer Library&lt;br /&gt;&lt;a href="http://www.symbian.com/developer/techlib/v9.1docs/doc_source/guide/Base-subsystem-guide/N10086/BuffersAndStrings/Descriptors/DescriptorsGuide3/FormatStringSyntax.guide.html#Descriptors%2eFormat%2dstring%2dsyntax"&gt;www.symbian.com/developer/techlib/v9.1docs/doc_source/guide/Base-subsystem-guide/N10086/BuffersAndStrings/Descriptors/DescriptorsGuide3/FormatStringSyntax.guide.html#Descriptors%2eFormat%2dstring%2dsyntax&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Reference [4] &lt;/span&gt;Pointer Descriptors Guide in the Symbian Developer Library&lt;br /&gt;&lt;a href="http://www.symbian.com/developer/techlib/v9.1docs/doc_source/guide/Base-subsystem-guide/N10086/BuffersAndStrings/Descriptors/DescriptorsGuide2/PointerDescriptors.guide.html#DescriptorsGuide2%2epointers"&gt;www.symbian.com/developer/techlib/v9.1docs/doc_source/guide/Base-subsystem-guide/N10086/BuffersAndStrings/Descriptors/DescriptorsGuide2/PointerDescriptors.guide.html#DescriptorsGuide2%2epointers&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Reference [5]&lt;/span&gt; Buffer Descriptors Guide in the Symbian Developer Library&lt;br /&gt;&lt;a href="http://www.symbian.com/developer/techlib/v9.1docs/doc_source/guide/Base-subsystem-guide/N10086/BuffersAndStrings/Descriptors/DescriptorsGuide2/BufferDescriptors.guide.html#DescriptorsGuide2%2ebuffers"&gt;www.symbian.com/developer/techlib/v9.1docs/doc_source/guide/Base-subsystem-guide/N10086/BuffersAndStrings/Descriptors/DescriptorsGuide2/BufferDescriptors.guide.html#DescriptorsGuide2%2ebuffers&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Reference [6]&lt;/span&gt; Documentation for &lt;span style="font-family:courier new;"&gt;RBuf&lt;/span&gt; in the Symbian Developer Library&lt;br /&gt;&lt;a href="http://www.symbian.com/developer/techlib/v9.1docs/doc_source/guide/Base-subsystem-guide/N10086/BuffersAndStrings/Descriptors/DescriptorsGuide2/ResizableBufferDescriptors.guide.html#DescriptorsGuide2%2eresizable"&gt;www.symbian.com/developer/techlib/v9.1docs/doc_source/guide/Base-subsystem-guide/N10086/BuffersAndStrings/Descriptors/DescriptorsGuide2/ResizableBufferDescriptors.guide.html#DescriptorsGuide2%2eresizable&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;"Introducing the &lt;span style="font-family:courier new;"&gt;RBuf&lt;/span&gt; Descriptor" Mark Shackman, Symbian:&lt;br /&gt;&lt;a href="http://www.symbian.com/developer/techlib/papers/rbuf/introduction_to_rbuf_v1.0.pdf"&gt;www.symbian.com/developer/techlib/papers/rbuf/introduction_to_rbuf_v1.0.pdf&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Reference [7]&lt;/span&gt; Forum Nokia: "Symbian OS: Descriptors For Text And Binary Data (With Example) v1.0"&lt;br /&gt;&lt;a href="http://www.forum.nokia.com/info/sw.nokia.com/id/7ad95f0e-d7aa-4acc-90f1-890e21207b75/Symbian_OS_Descriptors_For_Text_And_Binary_Data_With_Example_v1_0.zip.html"&gt;www.forum.nokia.com/info/sw.nokia.com/id/7ad95f0e-d7aa-4acc-90f1-890e21207b75/Symbian_OS_Descriptors_For_Text_And_Binary_Data_With_Example_v1_0.zip.html&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Reference [8]&lt;/span&gt; Reverse Polish Notation&lt;br /&gt;&lt;a href="http://www.calculator.org/rpn.html"&gt;www.calculator.org/rpn.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Reference [9]&lt;/span&gt; Reference information about &lt;span style="font-family:courier new;"&gt;TLex&lt;/span&gt; in the Symbian Developer Library&lt;br /&gt;&lt;a href="http://www.symbian.com/developer/techlib/v9.1docs/doc_source/reference/reference-cpp/N101CA/TLex16Class.html#%3a%3aTLex16"&gt;www.symbian.com/developer/techlib/v9.1docs/doc_source/reference/reference-cpp/N101CA/TLex16Class.html#%3a%3aTLex16&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Reference [10]&lt;/span&gt; Lexical analysis and &lt;span style="font-family:courier new;"&gt;TLex&lt;/span&gt; in the Symbian Developer Library&lt;br /&gt;&lt;br /&gt;Lexical analysis overview&lt;br /&gt;&lt;a href="http://www.symbian.com/developer/techlib/v9.1docs/doc_source/guide/Base-subsystem-guide/N10086/BuffersAndStrings/LexicalAnalysisOverview.guide.html#BuffersAndStringsOverview%2eLexicalAnalysisOverview%2emain"&gt;www.symbian.com/developer/techlib/v9.1docs/doc_source/guide/Base-subsystem-guide/N10086/BuffersAndStrings/LexicalAnalysisOverview.guide.html#BuffersAndStringsOverview%2eLexicalAnalysisOverview%2emain&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Using lexical analysis&lt;br /&gt;&lt;a href="http://www.symbian.com/developer/techlib/v9.1docs/doc_source/guide/Base-subsystem-guide/N10086/BuffersAndStrings/LexicalAnalysis/index.html#LexicalAnalysisGuide%2etoc"&gt;www.symbian.com/developer/techlib/v9.1docs/doc_source/guide/Base-subsystem-guide/N10086/BuffersAndStrings/LexicalAnalysis/index.html#LexicalAnalysisGuide%2etoc&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-114824629456262238?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/114824629456262238/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=114824629456262238' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/114824629456262238'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/114824629456262238'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2006/05/references-to-other-descriptors.html' title='References to other descriptors resources'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-114608160202540642</id><published>2006-04-26T12:52:00.000-07:00</published><updated>2006-04-26T19:43:15.243-07:00</updated><title type='text'>10,000 hits!</title><content type='html'>My hit counter (&lt;a href="http://www.statcounter.com"&gt;www.statcounter.com&lt;/a&gt;) informs me that this blog clocked over 10,000 hits today.  Thanks everyone for visiting over the last few months!  &lt;br /&gt;&lt;br /&gt;The blogs have been running for about a year now and are overdue for a makeover.  I'm hoping to make some changes to the format and include more regular updates and new content in the near future.  This will probably include moving them to a new home.  But don't worry, the current content won't be removed and there will be plenty of notice of any changes.&lt;br /&gt;&lt;br /&gt;Besides this blog, I'd just like to flag another descriptors resource on the web.  Take a look at &lt;a href="http://www.symbian.com/developer/tech_papers/papers/cpp_gettingstarted.asp#descriptors"&gt;this presentation&lt;/a&gt; on the Symbian site, for another view of descriptors. &lt;br /&gt;&lt;br /&gt;Best wishes,&lt;br /&gt;&lt;br /&gt;Jo&lt;br /&gt;Vancouver, April 26th 2006&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-114608160202540642?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/114608160202540642/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=114608160202540642' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/114608160202540642'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/114608160202540642'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2006/04/10000-hits.html' title='10,000 hits!'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-112336008550586664</id><published>2005-08-06T13:18:00.000-07:00</published><updated>2006-05-22T09:50:54.333-07:00</updated><title type='text'>35. How do I use TLex?</title><content type='html'>Well firstly, what is &lt;span style="font-family:courier new;"&gt;TLex&lt;/span&gt;?&lt;br /&gt;&lt;br /&gt;It's a lexical analysis class and the lexer example code, which comes with the Symbian OS SDK, gives one example of how to use it. You can find a brief description of the lexer example in the Symbian Developer Library documentation which comes with each SDK; it is also available on the Symbian website (see the &lt;span style="font-style: italic;"&gt;&lt;a href="http://descriptors.blogspot.com/2006/05/references-to-other-descriptors.html"&gt;References&lt;/a&gt;&lt;/span&gt; section for details).&lt;br /&gt;&lt;br /&gt;And, in case you're in some doubt as to what the lexer example is doing - I did - [&lt;a href="http://descriptors.blogspot.com/2006/05/references-to-other-descriptors.html"&gt;&lt;i&gt;reference 8&lt;/i&gt;&lt;/a&gt;] is a very useful resource about Reverse Polish Notation.&lt;br /&gt;&lt;br /&gt;The rest of this article will summarise the main features of &lt;span style="font-family:courier new;"&gt;TLex &lt;/span&gt;into groups of useful API calls. I'd like to create another, simple, example of how to use the class, but am a bit stuck for ideas of what would be useful. &lt;span style="font-weight: bold;"&gt;If anyone's got any thoughts on how best to illustrate the main features, please do add a comment to this post and I'll see what I can do&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;The main class, &lt;span style="font-family:courier new;"&gt;TLex&lt;/span&gt;, is like the descriptors in that two classes are available, &lt;span style="font-family:courier new;"&gt;TLex8&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;TLex1&lt;/span&gt;6 and the neutral version, &lt;span style="font-family:courier new;"&gt;TLex&lt;/span&gt;, is a typedef to &lt;span style="font-family:courier new;"&gt;TLex16&lt;/span&gt; for today's UNICODE builds of Symbian OS. You can find the Symbian API reference documentation for &lt;span style="font-family:courier new;"&gt;TLex16&lt;/span&gt; in [&lt;a href="http://descriptors.blogspot.com/2006/05/references-to-other-descriptors.html"&gt;&lt;i&gt;reference 9&lt;/i&gt;&lt;/a&gt;].&lt;br /&gt;&lt;br /&gt;As the documentation states, &lt;span style="font-family:courier new;"&gt;TLex &lt;/span&gt;"&lt;span style="font-style: italic;"&gt;...provides general string-parsing functions suitable for numeric format conversions and syntactical-element parsing...An instance of this class stores a string, maintaining an extraction mark to indicate the current lexical element being analysed and a pointer to the next character to be examined...&lt;/span&gt;"&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;TLex &lt;/span&gt;can be constructed with the data for lexical analysis or constructed empty and later assigned the data. Both construction and assignment take either another &lt;span style="font-family:courier new;"&gt;TLex &lt;/span&gt;object, a 16 bit non-modifiable descriptor or a &lt;span style="font-family:courier new;"&gt;TUint16*&lt;/span&gt; pointer to string data.&lt;br /&gt;&lt;br /&gt;At the very simplest level, when the string contains just numerical data, the descriptor contents can be converted to an integer by using the &lt;span style="font-family:courier new;"&gt;Val()&lt;/span&gt; function of &lt;span style="font-family:courier new;"&gt;TLex&lt;/span&gt;. For example:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    _LIT(KTestString1, "54321");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    TLex lex(KTestString1());&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    TInt value = 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    User::LeaveIfError(lex.Val(value));&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    ASSERT(value==54321);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The &lt;span style="font-family:courier new;"&gt;Val()&lt;/span&gt; function is overloaded for different signed integer types: &lt;span style="font-family:courier new;"&gt;TInt&lt;/span&gt;, &lt;span style="font-family:courier new;"&gt;TInt8&lt;/span&gt;, &lt;span style="font-family:courier new;"&gt;TInt16&lt;/span&gt;, &lt;span style="font-family:courier new;"&gt;TInt32&lt;/span&gt;, &lt;span style="font-family:courier new;"&gt;TInt64 &lt;/span&gt;- with or without limit checking. Likewise, there are &lt;span style="font-family:courier new;"&gt;Val()&lt;/span&gt; overloads for the unsigned integer types, passing in a radix type (decimal, hexadecimal, binary or octal). There are also overloads of &lt;span style="font-family:courier new;"&gt;Val()&lt;/span&gt; for &lt;span style="font-family:courier new;"&gt;TReal&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;However, there's a lot more you can do with &lt;span style="font-family:courier new;"&gt;TLex&lt;/span&gt;.  The Symbian Developer Library has more information about lexical analysis with TLex - see [&lt;a href="http://descriptors.blogspot.com/2006/05/references-to-other-descriptors.html"&gt;&lt;i&gt;reference 10&lt;/i&gt;&lt;/a&gt;] for more information.&lt;br /&gt;&lt;br /&gt;For example, you can move through the string using the &lt;span style="font-family:courier new;"&gt;Inc()&lt;/span&gt; functions, or just inspect each character using &lt;span style="font-family:courier new;"&gt;Peek()&lt;/span&gt;. Calling &lt;span style="font-family:courier new;"&gt;Get()&lt;/span&gt; will both increment the position and return the character - it can be reversed using &lt;span style="font-family:courier new;"&gt;UnGet()&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;You can skip whitespace using &lt;span style="font-family:courier new;"&gt;SkipSpace()&lt;/span&gt; or characters using &lt;span style="font-family:courier new;"&gt;SkipCharacters()&lt;/span&gt;. The end of the string is hit when &lt;span style="font-family:courier new;"&gt;EoS()&lt;/span&gt; returns &lt;span style="font-family:courier new;"&gt;ETrue&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;You can put an extraction marker at position in the string, using the &lt;span style="font-family:courier new;"&gt;Mark()&lt;/span&gt; overloads. Marking is also useful if you want to reverse (&lt;span style="font-family:courier new;"&gt;UnGetToMark()&lt;/span&gt; or skip using &lt;span style="font-family:courier new;"&gt;SkipAndMark()&lt;/span&gt; or &lt;span style="font-family:courier new;"&gt;SkipSpaceAndMark()&lt;/span&gt;).&lt;br /&gt;&lt;br /&gt;Tokens are used to describe a character string which is deliminated by white space. There are a number of token methods available, such as &lt;span style="font-family:courier new;"&gt;TokenLength()&lt;/span&gt;, &lt;span style="font-family:courier new;"&gt;MarkedToken()&lt;/span&gt; - which extracts a token - and &lt;span style="font-family:courier new;"&gt;NextToken()&lt;/span&gt;. If you don't use tokens, you can use offsets and remainders instead - there are a number of methods for navigating the string in this way.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-112336008550586664?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/112336008550586664/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=112336008550586664' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/112336008550586664'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/112336008550586664'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/08/35-how-do-i-use-tlex.html' title='35. How do I use TLex?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111991813918983401</id><published>2005-06-27T17:20:00.000-07:00</published><updated>2006-05-21T16:33:51.620-07:00</updated><title type='text'>34. Is there a way to get binary data in a _LIT?</title><content type='html'>Check out the answer to FAQ-0814 on Symbian's Developer FAQ &amp; Tech Tips site:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www3.symbian.com/faq.nsf/0/D5889EFF80ED87B780256C290051923C?OpenDocument"&gt;Is there a way to get binary data in a _LIT?&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111991813918983401?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111991813918983401/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111991813918983401' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111991813918983401'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111991813918983401'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/06/34-is-there-way-to-get-binary-data-in.html' title='34. Is there a way to get binary data in a _LIT?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111983988043376901</id><published>2005-06-26T19:28:00.000-07:00</published><updated>2006-05-18T13:26:48.166-07:00</updated><title type='text'>33. Can you give an example of how to use RBuf?</title><content type='html'>Yes. I was initially reluctant to do so, because there isn't any published example code out there yet. But I'll take the plunge with this example, which shows how to use &lt;span style="font-family:courier new;"&gt;RBuf16&lt;/span&gt;.  I'll leave code to use &lt;span style="font-family:courier new;"&gt;RBuf8&lt;/span&gt;, and to use the non-leaving &lt;span style="font-family:courier new;"&gt;Create()&lt;/span&gt; methods as an exercise for the reader, for now.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;void ExampleRBufCodeL()&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;{&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;__UHEAP_MARK;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;//  RBuf::CreateL&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    RBuf modifiableBuf;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    modifiableBuf.CreateL(12);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    ASSERT(modifiableBuf.Length()==0);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    ASSERT(modifiableBuf.MaxLength()==12);&lt;br /&gt;...&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt; &lt;span style="font-size:85%;"&gt;// Do stuff. First push modifiableBuf onto the cleanup stack if a leave may occur&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    modifiableBuf.Close();&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;//  RBuf::CreateMaxL&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    modifiableBuf.CreateMaxL(12);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    ASSERT(modifiableBuf.Length()==12);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    ASSERT(modifiableBuf.MaxLength()==12);&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;...&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt; &lt;span style="font-size:85%;"&gt;// Do stuff. First push modifiableBuf onto the cleanup stack if a leave may occur&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;    modifiableBuf.Close();&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;//  RBuf::CreateL passing in a descriptor&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    _LIT(KHelloWorld, "Hello World");&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    modifiableBuf.CreateL(KHelloWorld());&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    ASSERT(modifiableBuf.Length()==11);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    ASSERT(modifiableBuf.MaxLength()==11);&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;...&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt; &lt;span style="font-size:85%;"&gt;// Do stuff. First push modifiableBuf onto the cleanup stack if a leave may occur&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;    modifiableBuf.Close();&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;//  RBuf::CreateL passing in a descriptor and a maximum length&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;modifiableBuf.CreateL(KHelloWorld(), 15);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    ASSERT(modifiableBuf.Length()==11);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    ASSERT(modifiableBuf.MaxLength()==15);&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;...&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt; &lt;span style="font-size:85%;"&gt;// Do stuff. First push modifiableBuf onto the cleanup stack if a leave may occur&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;    modifiableBuf.Close()&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;//  RBuf::CreateL and ReAllocL &amp; modifiable descriptor base class methods&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;_LIT(KHello, "Hello");&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    _LIT(KWorld, " World");&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    modifiableBuf.CreateL(5);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    modifiableBuf.Copy(KHello());&lt;br /&gt;modifiableBuf.CleanupClosePushL(); &lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;// Push onto cleanup stack for leave safety&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    modifiableBuf.ReAllocL(11);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    modifiableBuf.Append(KWorld);&lt;br /&gt;CleanupStack::PopAndDestroy(); &lt;span style="color: rgb(0, 153, 0);"&gt;// Calls modifiableBuf.Close()&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;//  RBuf::Assign&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;HBufC* hBuf = KHello().AllocL();&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    modifiableBuf.Assign(hBuf);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    ASSERT(modifiableBuf.Length()==5);&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;...&lt;span style="color: rgb(0, 153, 0);font-size:85%;" &gt; &lt;span style="font-size:85%;"&gt;// Do stuff. First push modifiableBuf onto the cleanup stack if a leave may occur&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;    modifiableBuf.Close();&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 153, 0);font-family:courier new;" &gt;//  RBuf::Assign, ReAllocL and use of TDes::Append&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    TUint16* ptr = static_cast&lt;tuint16&gt;(User::AllocL(5*sizeof(TText)));&lt;br /&gt;&lt;/tuint16&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    modifiableBuf.Assign(ptr,5);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    ASSERT(modifiableBuf.Length()==0);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    modifiableBuf.Copy(KHello()); &lt;span style="color: rgb(0, 153, 0);"&gt;// Copying any more would panic&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;modifiableBuf.CleanupClosePushL(); &lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;// Push onto cleanup stack for leave safety&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;modifiableBuf.ReAllocL(12);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    modifiableBuf.Append(KWorld);&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;CleanupStack::PopAndDestroy(); &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;// Calls modifiableBuf.Close()&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt; &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    __UHEAP_MARKEND;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111983988043376901?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111983988043376901/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111983988043376901' title='13 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111983988043376901'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111983988043376901'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/06/33-can-you-give-example-of-how-to-use.html' title='33. Can you give an example of how to use RBuf?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>13</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111983854094659932</id><published>2005-06-26T18:54:00.000-07:00</published><updated>2006-05-22T13:11:43.346-07:00</updated><title type='text'>32. How do I use RBuf?  What is it?</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;From the Symbian OS 8.1a SDK&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-family:courier new;" &gt;RBuf16&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;16-bit resizable buffer descriptor &lt;span style="font-style: italic;"&gt;[Jo comments - an equivalent 8-bit version, RBuf8, also exists]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The class provides a buffer that contains, accesses and manipulates &lt;span style="font-family:courier new;"&gt;TUint16&lt;/span&gt; data. The buffer itself is on the heap, and is managed by the class.&lt;br /&gt;&lt;br /&gt;Internally, &lt;span style="font-family:courier new;"&gt;RBuf16&lt;/span&gt; behaves in one of two ways:&lt;br /&gt;&lt;br /&gt;* as a &lt;span style="font-family:courier new;"&gt;TPtr16&lt;/span&gt; descriptor type, where the buffer just contains data,&lt;br /&gt;* as a pointer to a heap descriptor, an &lt;span style="font-family:courier new;"&gt;HBufC16*&lt;/span&gt; type, where the buffer contains both descriptor information and the data.&lt;br /&gt;&lt;br /&gt;Note that the handling of the distinction is hidden from view.&lt;br /&gt;&lt;br /&gt;An &lt;span style="font-family:courier new;"&gt;RBuf16&lt;/span&gt; object can allocate its own buffer. Alternatively, it can take ownership of a pre-existing section of allocated memory, or it can take ownership of a pre-existing heap descriptor. It can also reallocate the buffer to resize it. Regardless of the way in which the buffer has been allocated, the &lt;span style="font-family:courier new;"&gt;RBuf16&lt;/span&gt; object is responsible for freeing memory when the object itself is closed.&lt;br /&gt;&lt;br /&gt;The class is intended for instantiation.&lt;br /&gt;The class is derived from &lt;span style="font-family:courier new;"&gt;TDes16&lt;/span&gt;, which means that data can be both accessed and modified. The base classes provide the functions through which the data is accessed. In addition, an &lt;span style="font-family:courier new;"&gt;RBuf16&lt;/span&gt; object can be passed to any function that is prototyped to take a &lt;span style="font-family:courier new;"&gt;TDes16&lt;/span&gt; or a &lt;span style="font-family:courier new;"&gt;TDesC16&lt;/span&gt; type.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;So what does this mean for me?&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;An &lt;span style="font-family:courier new;"&gt;RBuf&lt;/span&gt; object is rather like an &lt;span style="font-family:courier new;"&gt;HBufC&lt;/span&gt; in that it can be created dynamically by specifying the maximum length required. However, it also benefits from being modifiable, since it derives from &lt;span style="font-family:courier new;"&gt;TDes16&lt;/span&gt;. This means that you don’t have to create a &lt;span style="font-family:courier new;"&gt;TPtr &lt;/span&gt;around the data in order to modify it, which makes it preferable to &lt;span style="font-family:courier new;"&gt;HBufC &lt;/span&gt;when you know you need to dynamically allocate a descriptor, and later modify it.&lt;br /&gt;&lt;br /&gt;You don’t need to worry too much about how it’s represented internally – either as a &lt;span style="font-family:courier new;"&gt;TPtr &lt;/span&gt;or &lt;span style="font-family:courier new;"&gt;HBufC&lt;/span&gt;. In fact, all you need to know is how to create and destroy an &lt;span style="font-family:courier new;"&gt;RBuf&lt;/span&gt;, because calling the other descriptor operations on it should be second nature, given that you have access to all the base class methods of &lt;span style="font-family:courier new;"&gt;TDes16 &lt;/span&gt;and &lt;span style="font-family:courier new;"&gt;TDes16C&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;But you must remember that, although &lt;span style="font-family:courier new;"&gt;RBuf &lt;/span&gt;manages the descriptor buffer by freeing it when you call &lt;span style="font-family:courier new;"&gt;Close()&lt;/span&gt;, it doesn’t manage the size of the buffer and reallocate it when you need more memory for any particular operation.&lt;br /&gt;&lt;br /&gt;So, for example, if you call &lt;span style="font-family:courier new;"&gt;Append() &lt;/span&gt;on a &lt;span style="font-family:courier new;"&gt;RBuf &lt;/span&gt;object for which there is insufficient memory available, a panic will occur – the &lt;span style="font-family:courier new;"&gt;RBuf &lt;/span&gt;object will not automatically reallocate the buffer. This should be clear from the fact that the base class methods are non-leaving, that is, there is no scope for the reallocation to fail in the event of low memory.&lt;br /&gt;&lt;br /&gt;So you still need to manage the memory for descriptor operations that may need to extend the descriptor.&lt;br /&gt;&lt;br /&gt;The &lt;span style="font-family:courier new;"&gt;RBuf &lt;/span&gt;class was first introduced in Symbian OS v8.0, but first documented in the 8.1 SDK and is used extensively in software written for devices based on v9.x.  The RBuf class is ideal for handling &lt;span style="font-family:courier new;"&gt;HBufC &lt;/span&gt;using a stack-based R class object, and may often be preferable to the contortions required to modify an &lt;span style="font-family:courier new;"&gt;HBufC&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;I've created a short example of how to use the class in &lt;a href="http://descriptors.blogspot.com/2005/06/33-can-you-give-example-of-how-to-use.html"&gt;&lt;i&gt;33. Can you give an example of how to use RBuf?&lt;/i&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I'd like to acknowledge &lt;a href="http://www.pagonis.org/Pagonis.html"&gt;JP&lt;/a&gt;'s help and advice with this post.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111983854094659932?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111983854094659932/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111983854094659932' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111983854094659932'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111983854094659932'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/06/32-how-do-i-use-rbuf-what-is-it.html' title='32. How do I use RBuf?  What is it?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111964615373197862</id><published>2005-06-24T13:42:00.000-07:00</published><updated>2006-05-21T16:26:52.853-07:00</updated><title type='text'>31. How do I convert between Java strings and descriptors?</title><content type='html'>Check out the answer to FAQ-0277 on Symbian's Developer FAQ &amp; Tech Tips site:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www3.symbian.com/faq.nsf/0/80D8199F9B71BC6180256A570051BA7E?OpenDocument"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family: georgia;"&gt;"&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: georgia;font-family:Arial;font-size:100%;"  &gt;How do I convert between Java strings and Unicode descriptors?"&lt;/span&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111964615373197862?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111964615373197862/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111964615373197862' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111964615373197862'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111964615373197862'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/06/31-how-do-i-convert-between-java.html' title='31. How do I convert between Java strings and descriptors?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111963942230807890</id><published>2005-06-24T11:52:00.000-07:00</published><updated>2006-05-21T16:25:03.310-07:00</updated><title type='text'>30. How do I convert an 8-bit descriptor to a Java string?</title><content type='html'>Check out the answer to FAQ-0298 on Symbian's Developer FAQ &amp; Tech Tips site:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;a href="http://www3.symbian.com/faq.nsf/0/B2CF51949A6B8AAD80256A570051BA7C?OpenDocument"&gt;&lt;span style="font-family:georgia;"&gt;"&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;a href="http://www3.symbian.com/faq.nsf/0/B2CF51949A6B8AAD80256A570051BA7C?OpenDocument"&gt;&lt;span style=";font-family:Arial;font-size:100%;"  &gt;How do I convert an 8-bit descriptor to a Java string?&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:100%;"&gt;&lt;a href="http://www3.symbian.com/faq.nsf/0/B2CF51949A6B8AAD80256A570051BA7C?OpenDocument"&gt;&lt;span style="font-family:georgia;"&gt;"&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;These days, it's not necessary to use the Symbian cast macros (eg REINTERPRET_CAST) since these are simply defined as the equivalent C++ standard (eg reinterpret_cast). They're a legacy from when GCC didn't support &lt;/span&gt;the casts.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111963942230807890?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111963942230807890/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111963942230807890' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111963942230807890'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111963942230807890'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/06/30-how-do-i-convert-8-bit-descriptor.html' title='30. How do I convert an 8-bit descriptor to a Java string?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111904410056936718</id><published>2005-06-17T14:29:00.000-07:00</published><updated>2006-05-21T16:23:40.826-07:00</updated><title type='text'>29. How can I write the most efficient code when using HBufC?</title><content type='html'>&lt;span style="font-weight: bold;"&gt;(1) Spawn &lt;span style="font-family:courier new;"&gt;HBufC &lt;/span&gt;from existing descriptors using &lt;span style="font-family:courier new;"&gt;TDesC::AllocL()&lt;/span&gt; rather than creating and copying into them&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;HBufC &lt;/span&gt;can be spawned from a existing descriptor using the &lt;span style="font-family:courier new;"&gt;Alloc()&lt;/span&gt; or &lt;span style="font-family:courier new;"&gt;AllocL()&lt;/span&gt; overloads of by &lt;span style="font-family:courier new;"&gt;TDesC&lt;/span&gt;.  You can thus replace code like this:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;void SomeFunctionL(const TDesC&amp; aDes)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    HBufC* heapBuffer = HBufC::NewL(aDes.Length());&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    TPtr ptr(heapBuffer-&gt;Des());&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    ptr.Copy(aDes);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    ...&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;With the more efficient single line:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;void SomeFunctionL(const TDesC&amp; aDes)&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    HBufC* heapBuffer = aDes.AllocL();&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;    ...&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(2) Don't call &lt;span style="font-family:courier new;"&gt;HBufC::Des()&lt;/span&gt; if you need only non-modifiable access to the data&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;It is clearer and more efficient simply to dereference an &lt;span style="font-family:courier new;"&gt;HBufC &lt;/span&gt;if you need a non modifiable reference to its data.  You only need to call &lt;span style="font-family:courier new;"&gt;Des()&lt;/span&gt; when you need to modify it - &lt;span style="font-family:courier new;"&gt;Des()&lt;/span&gt; will return a &lt;span style="font-family:courier new;"&gt;TPtr&lt;/span&gt;.  That is:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;void Log(const TDesC&amp; aLogBuf); // Forward declaration&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;void Convert(TDes&amp; aBuf);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;void CMyClass::SomeFunction()&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;{// iHeapBuf is a member of CMyClass&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;//  Get non-modifiable access (TDesC&amp;) to iHeapBuf&lt;br /&gt; &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;Log(*iHeapBuf); // Call a method which takes const TDesC&amp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;//  Now get modifiable access (TDes&amp;amp;) to iHeapBuf&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt; Convert(iHeapBuf-&gt;Des()); // Call a method which takes TDes&amp;amp;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;By the way, an interesting side-effect of creating a modifiable descriptor from a non-modifiable heap descriptor is discussed in &lt;a href="http://descriptor-tips.blogspot.com/2005/06/tip-9-beware-of-calling-maxlength-on.html"&gt;Tip 9&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111904410056936718?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111904410056936718/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111904410056936718' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111904410056936718'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111904410056936718'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/06/29-how-can-i-write-most-efficient-code.html' title='29. How can I write the most efficient code when using HBufC?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111903394805324911</id><published>2005-06-17T11:38:00.000-07:00</published><updated>2006-05-21T16:20:17.243-07:00</updated><title type='text'>28. How do I know what the equivalent C string library functions are for descriptors?</title><content type='html'>Just about all the C string library functionality has been implemented by the descriptor base classes, so you can chop them up, rearrange, tokenise and format them just like you have always been able to do with C strings.&lt;br /&gt;&lt;br /&gt;Here's a useful &lt;a href="http://www.whoshavesthebarber.com/descriptors_blog/cstringanddescriptors.html"&gt;table&lt;/a&gt; which compares C string functions with their descriptor equivalents.  I found the information in section 5 of [&lt;a href="http://descriptors.blogspot.com/2006/05/references-to-other-descriptors.html"&gt;&lt;i&gt;reference 7&lt;/i&gt;&lt;/a&gt;]&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111903394805324911?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111903394805324911/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111903394805324911' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111903394805324911'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111903394805324911'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/06/28-how-do-i-know-what-equivalent-c.html' title='28. How do I know what the equivalent C string library functions are for descriptors?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111870463553504929</id><published>2005-06-13T16:15:00.000-07:00</published><updated>2006-05-21T16:02:10.413-07:00</updated><title type='text'>27. How do I know which kind of descriptor to use?</title><content type='html'>This flowchart may help.  It's taken from my book, Symbian OS Explained (page 76), with some modification:&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.whoshavesthebarber.com/descriptors_blog/Descriptor_flowchart.jpg" /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111870463553504929?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111870463553504929/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111870463553504929' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111870463553504929'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111870463553504929'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/06/27-how-do-i-know-which-kind-of.html' title='27. How do I know which kind of descriptor to use?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111862790015515670</id><published>2005-06-12T18:49:00.000-07:00</published><updated>2006-05-18T13:24:51.993-07:00</updated><title type='text'>26. How do I convert between 8 bit and 16 bit descriptors?</title><content type='html'>TDes defines a set of &lt;span style="font-family:courier new;"&gt;Copy()&lt;/span&gt; methods to copy data from another descriptor of either width, from a pointer to a block of data of a specified length or from a NULL-terminated string. There are also methods for copying with folding,collation or case adjustment.&lt;br /&gt;&lt;br /&gt;In each case, the data is copied &lt;span style="font-weight: bold;"&gt;*from*&lt;/span&gt; the source specified in the parameter &lt;span style="font-weight: bold;"&gt;*into*&lt;/span&gt; the modifiable, target, descriptor upon which the method is called. If the length of the 'incoming' data is greater than the target descriptor, a USER 11 panic occurs.&lt;br /&gt;&lt;br /&gt;// From the definition of &lt;span style="font-family:courier new;"&gt;TDes16&lt;/span&gt; in e32des16.h&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;IMPORT_C void Copy(const TDesC8&amp; aDes); // Copies an 8 bit descriptor&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;IMPORT_C void Copy(const TDesC16&amp; aDes); // Copies a 16 bit descriptor&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;IMPORT_C void Copy(const TUint16* aBuf, TInt aLength); // Copies aLength characters from the aBuf pointer&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;IMPORT_C void Copy(const TUint16* aString); // Copies the NULL terminated aString&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;IMPORT_C void CopyF(const TDesC16&amp; aDes); // Copies and folds&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;IMPORT_C void CopyC(const TDesC16&amp; aDes); // Copies and collates&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;IMPORT_C void CopyLC(const TDesC16&amp; aDes); // Copies and converts the text to lower case&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;IMPORT_C void CopyUC(const TDesC16&amp; aDes); // Copies and converts the text to upper case&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;IMPORT_C void CopyCP(const TDesC16&amp; aDes); // Copies and capitalizes the text&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Note that, because the &lt;span style="font-family:courier new;"&gt;Copy()&lt;/span&gt; method is overloaded to take either an 8- or 16-bit descriptor, it is possible to copy:&lt;br /&gt;&lt;ul&gt;   &lt;li&gt;a narrow descriptor onto a narrow descriptor (&lt;span style="font-family:courier new;"&gt;TDes8 -&gt; TDes8&lt;/span&gt;), &lt;/li&gt;   &lt;li&gt;a wide descriptor onto a wide descriptor (&lt;span style="font-family:courier new;"&gt;TDes16 -&gt; TDes16&lt;/span&gt;), &lt;/li&gt;   &lt;li&gt;a narrow descriptor onto a wide descriptor (&lt;span style="font-family:courier new;"&gt;TDes8 -&gt; TDes16&lt;/span&gt;),&lt;/li&gt;   &lt;li&gt;a wide descriptor onto a narrow descriptor (&lt;span style="font-family:courier new;"&gt;TDes16 -&gt; TDes8&lt;/span&gt;).&lt;/li&gt; &lt;/ul&gt;&lt;br /&gt;Copying between descriptors of equivalent character widths is fairly self-explanatory, but copying between descriptors of different character widths is worthy of elaboration:&lt;br /&gt;&lt;br /&gt;The &lt;span style="font-family:courier new;"&gt;Copy()&lt;/span&gt; method implemented by &lt;span style="font-family:courier new;"&gt;TDes16&lt;/span&gt; to copy an 8 bit descriptor parameter will pad each incoming character with a trailing zero.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;// Instantiate a wide descriptor&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;_LIT16(KFred, "Fred");&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;TBuf16&lt;4&gt; wideFred(KFred); // Bytewise = F\0R\0E\0D\0&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;// Instantiate a narrow descriptor&lt;/span&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;br /&gt;_LIT8(KBert, "Bert");&lt;/span&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;br /&gt;TBuf8&lt;5&gt; narrowBert(KBert); // Bytewise = BERT&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;// Copy the contents of the narrow descriptor into the wide descriptor&lt;/span&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;br /&gt;wideFred.Copy(narrowBert); // Bytewise = B\0E\0R\0T\0&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;The &lt;span style="font-family:courier new;"&gt;Copy()&lt;/span&gt; method implemented by &lt;span style="font-family:courier new;"&gt;TDes8&lt;/span&gt; to copy an incoming 16-bit descriptor will strip out alternate characters which are assumed to be zeroes. This means that this form of copy will only work if the characters in the wide string do not exceed 255 (decimal).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;// Instantiate a wide descriptor&lt;/span&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;br /&gt;_LIT16(KFred, "Fred");&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;TBuf16&lt;4&gt; wideFred(KFred); // Bytewise = F\0R\0E\0D\0&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;// Instantiate a narrow descriptor&lt;/span&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;br /&gt;_LIT8(KBert, "Bert");&lt;/span&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;br /&gt;TBuf8&lt;5&gt; narrowBert(KBert); // Bytewise = BERT&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;// Copy the contents of the wide descriptor into the narrow descriptor&lt;/span&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;br /&gt;narrowBert.Copy(wideFred); // Bytewise = FRED&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;&lt;br /&gt;Copy()&lt;/span&gt; thus forms a simple way to copy and convert between narrow and wide descriptors when the character set is encoded by one 8-bit byte per character and the last byte of each wide character is simply a NULL character padding.&lt;br /&gt;&lt;br /&gt;If you need to do a proper conversion between 16-bit Unicode and 8-bit, non-Unicode, character sets (or between Unicode and the UTF-7 and UTF-8 transformation sets), use the Symbian OS conversion library, charconv.lib.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111862790015515670?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111862790015515670/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111862790015515670' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111862790015515670'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111862790015515670'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/06/26-how-do-i-convert-between-8-bit-and.html' title='26. How do I convert between 8 bit and 16 bit descriptors?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111862454595587801</id><published>2005-06-12T17:59:00.000-07:00</published><updated>2006-05-18T13:24:35.293-07:00</updated><title type='text'>25. What do Length(), MaxLength(), SetLength() and SetMax() do?</title><content type='html'>&lt;span style="font-weight: bold;font-family:courier new;" &gt;TDesC::Length()&lt;/span&gt; returns the number of characters the descriptor contains.&lt;br /&gt;&lt;br /&gt;[While we're on the subject of descriptor length, beware!  Be careful not to confuse &lt;span style="font-family:courier new;"&gt;Size()&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;Length()&lt;/span&gt;.  They do similar things, but while &lt;span style="font-family:courier new;"&gt;Length()&lt;/span&gt; returns the number of characters the descriptor contains, &lt;span style="font-family:courier new;"&gt;Size()&lt;/span&gt; returns the number of bytes it occupies. For 8-bit descriptors, where each character occupies a byte, this is the same thing. However, on all releases of Symbian OS since v5u, the native character width has been 16 bits, so each character occupies two bytes. Unless you're working with a very old SDK, you'll find that &lt;span style="font-family:courier new;"&gt;Size()&lt;/span&gt; always returns a value which is double that of &lt;span style="font-family:courier new;"&gt;Length()&lt;/span&gt;].&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:courier new;" &gt;TDes::MaxLength()&lt;/span&gt; returns the maximum length allowed for a modifiable descriptor.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:courier new;" &gt;TDes::SetLength()&lt;/span&gt; can be used to change the descriptor's length to any value between zero and its maximum length.  You can also use &lt;span style="font-family:courier new;"&gt;TDes::Zero()&lt;/span&gt; to set the length to zero.  And &lt;span style="font-weight: bold;font-family:courier new;" &gt;TDes::SetMax()&lt;/span&gt; to set the length to the maximum.&lt;br /&gt;&lt;br /&gt;[&lt;span style="font-family:courier new;"&gt;SetMax()&lt;/span&gt; has a slightly misleading name. It doesn’t allow you to change the maximum length of the descriptor, which would, in effect, allow you to resize its data area].&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111862454595587801?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111862454595587801/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111862454595587801' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111862454595587801'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111862454595587801'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/06/25-what-do-length-maxlength-setlength.html' title='25. What do Length(), MaxLength(), SetLength() and SetMax() do?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111732713064029816</id><published>2005-05-28T17:36:00.000-07:00</published><updated>2006-05-18T13:24:00.090-07:00</updated><title type='text'>23. Why is the _L literal descriptor macro deprecated?</title><content type='html'>Why is the original _L macro now deprecated in all but test code?  These have the advantage of being used in place rather than declared separately, for example:&lt;br /&gt;&lt;br /&gt;User::Panic(_L("TEST SERVER"), KErrNotOVerflow);&lt;br /&gt;&lt;br /&gt;You will still see them used in test code since they saves typing and thinking up a name for each literal.  It's OK to do so where memory use is not critical, but you should avoid using them in production code.  Why?&lt;br /&gt;&lt;br /&gt;Well, the text, for example "TEST SERVER" is built into ROM as a basic, NULL-terminated C style string, with no initial length member. Because the layout of the stored literal is not like that of a descriptor, it means that when each instance of the literal is used, a temporary TPtrC must be constructed around the data in ROM.  The construction of the temporary, which requires 4 bytes of memory for the length/type data, and instructions to set the pointer, the length and the descriptor type, is an unnecessary overhead when compared to _LIT descriptors which can be used directly because they are stored in ROM to look like descriptors. &lt;br /&gt;&lt;br /&gt;The generation of each temporary results in inline constructor code which may bloat binaries where many string literals are used.  Furthermore, the use of a run-time temporary is safe as long as it is used only during the lifetime of the function in which it is created&lt;br /&gt;&lt;br /&gt;So, in summary, you should use _LIT to _L for your literal descriptors, because _L has an overhead associated with constructing a run-time temporary TPtrC and _LIT does not.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111732713064029816?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111732713064029816/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111732713064029816' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111732713064029816'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111732713064029816'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/05/23-why-is-l-literal-descriptor-macro.html' title='23. Why is the _L literal descriptor macro deprecated?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111732695814236581</id><published>2005-05-28T17:34:00.000-07:00</published><updated>2006-05-28T14:23:32.643-07:00</updated><title type='text'>22. What are literal descriptors?</title><content type='html'>Literal descriptors are constant descriptors which are compiled into ROM because their contents does not ever change. They are equivalent to static char[] in C.&lt;br /&gt;&lt;br /&gt;There are two types of literal descriptor, _LIT which is the most efficient, and preferred, Symbian OS literal and _L, which is now deprecated in all but test code.&lt;br /&gt;&lt;br /&gt;In the examples I've included in this blog, I've used _LIT throughout, so you've seen it in action already, for example:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;_LIT(KFred, "Fred");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;On the wide builds of Symbian OS created today, this is equivalent to the following:&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;_LIT16(KFred, "Fred");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If an explicitly narrow literal descriptor is required, this can be created using the _LIT8 macro:&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;_LIT8(KFred, "Fred");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;KFred&lt;/span&gt; can then be used as a constant descriptor, either directly or to initialise a &lt;span style="font-family: courier new;"&gt;TPtrC/TPtr&lt;/span&gt; or &lt;span style="font-family: courier new;"&gt;TBufC/TBuf&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;The macros are defined in the Symbian OS header file e32def.h and create an object of type &lt;span style="font-family: courier new;"&gt;TLitC16&lt;/span&gt; or &lt;span style="font-family: courier new;"&gt;TLitC8&lt;/span&gt; (defined in e32des.h). These classes do not derive from &lt;span style="font-family: courier new;"&gt;TDesC8&lt;/span&gt; or &lt;span style="font-family: courier new;"&gt;TDesC16&lt;/span&gt; but have the same binary layout as &lt;span style="font-family: courier new;"&gt;TBufC8&lt;/span&gt; or &lt;span style="font-family: courier new;"&gt;TBufC16&lt;/span&gt;. This means that the literal object can be used wherever &lt;span style="font-family: courier new;"&gt;TDesC&lt;/span&gt; is used. The literal classes provide &lt;span style="font-family: courier new;"&gt;operator()()&lt;/span&gt; which is very useful to cast the literal object to a &lt;span style="font-family: courier new;"&gt;TDesC&lt;/span&gt;. For example:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;_LIT(KFred, "Fred");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;HBufC8* theHeapBuffer = KFred().AllocL();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To save you additional code, Symbian OS already defines a literal to represent a blank string, defined as follows:&lt;br /&gt;&lt;br /&gt;Build independent: &lt;span style="font-family: courier new;"&gt;_LIT(KNullDesC,"");&lt;/span&gt;&lt;br /&gt;8-bit for non-Unicode strings: &lt;span style="font-family: courier new;"&gt;_LIT8(KNullDesC8,"");&lt;/span&gt;&lt;br /&gt;16-bit for Unicode strings: &lt;span style="font-family: courier new;"&gt;_LIT16(KNullDesC16,"");&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111732695814236581?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111732695814236581/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111732695814236581' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111732695814236581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111732695814236581'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/05/22-what-are-literal-descriptors.html' title='22. What are literal descriptors?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111732443163932716</id><published>2005-05-28T16:53:00.000-07:00</published><updated>2006-05-22T09:47:39.543-07:00</updated><title type='text'>21. Why is there no HBuf class?</title><content type='html'>Well, there is and there isn't. Up until Symbian OS v8.0, there was no modifiable heap descriptor class, HBuf, in symmetry with the TBufC and TBuf stack buffers. There were a number of reasons for this:&lt;br /&gt;&lt;br /&gt;(1) The expectation might be that, for a modifiable heap descriptor, the maximum length would expand and contract on the heap as the content was modified. An HBuf class which is modifiable but does not dynamically resize could be considered odd and rather pointless. But to add dynamic resizing to HBuf would be difficult because these methods could leave under low memory conditions and would have to be adjusted accordingly. But, as I’ve previously described, all the modifiable descriptor operations are implemented in the base class, TDes, thus affecting all descriptor types.&lt;br /&gt;&lt;br /&gt;(2) If dynamic reallocation were added to HBuf, the location of the buffer might change as code is reallocated, affecting all TPtr objects referencing that heap buffer's data, as well as compromising the cleanup stack, if the HBuf pointer is stored there.&lt;br /&gt;&lt;br /&gt;(3) Heap buffers were initially intended to allow efficient reading of constant resource strings of variable length. Because they are constant, they save on the additional four bytes required to store a maximum length, which allows them to be as compact as possible. They can still be modified using Des() if necessary, If a separate HBuf class were provided, it would have an extra 4-byte overhead - and may frequently be created unnecessarily, which might add to a significant waste of heap space over time.&lt;br /&gt;&lt;br /&gt;However, this is a somewhat spurious argument since making an HBufC::Des() call is non-trivial and the resultant TPtr itself occupies 12 bytes of stack space. If a modifiable heap descriptor is definitely needed, creating a constant buffer and then an additional, TPtr to update wastes memory *and* processor instructions.&lt;br /&gt;&lt;br /&gt;To this end, Symbian OS 8.0 and 8.1 introduced class RBuf for resizable descriptors.  The Symbian documentation for this class can be found in [&lt;a href="http://descriptors.blogspot.com/2006/05/references-to-other-descriptors.html"&gt;&lt;i&gt;reference 6&lt;/i&gt;&lt;/a&gt;]. &lt;br /&gt;&lt;br /&gt;I discuss class RBuf in more detail in &lt;a href="http://descriptors.blogspot.com/2005/06/32-how-do-i-use-rbuf-what-is-it.html"&gt;&lt;i&gt;32. How do I use RBuf? What is it?&lt;/i&gt;&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111732443163932716?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111732443163932716/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111732443163932716' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111732443163932716'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111732443163932716'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/05/21-why-is-there-no-hbuf-class.html' title='21. Why is there no HBuf class?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111732190033486935</id><published>2005-05-28T16:05:00.000-07:00</published><updated>2007-09-18T11:44:32.886-07:00</updated><title type='text'>20. How do I use heap-based buffer descriptors?</title><content type='html'>Heap-based descriptors, HBufC&amp;lt;n&amp;gt;, can be used for dynamic allocation of string data whose size is not known at compile time.  It should also be used to store string data too large for the stack.  In effect, HBufC should be used where malloc’d data would be used in C.&lt;br /&gt;&lt;br /&gt;Although the class representing these descriptors is HBufC, these descriptors are always referred to by pointer, HBufC*. The class doesn’t comply with the standard Symbian OS naming conventions, but then, it doesn’t really fit any of the standard Symbian OS types exactly. It is simply prefixed with H to indicate that the data is stored on the heap.&lt;br /&gt;&lt;br /&gt;HBufC can be created using one of the static NewL() functions of the class.  These may leave if there is insufficient memory available (the non-leaving version will return NULL). The heap buffers must be constructed using one of these methods or by using one of the Alloc() or AllocL() methods of the TDesC class to spawn an HBufC copy of any descriptor.&lt;br /&gt;&lt;br /&gt;The ‘C’ suffix in the class name indicates that these descriptors are constant, although, in common with the stack-based non-modifiable buffer descriptors, the class has a set of assignment operators to allow the entire contents of the buffer to be replaced (as long as the new data does not exceed the length of the heap cell originally allocated).  In addition, as with TBufC, the heap-based descriptors can be manipulated at runtime by creating a modifiable pointer descriptor, TPtr over the heap buffer, using the Des() method.  For example:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;_LIT(KFred, "Fred");&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;// Allocate an empty heap descriptor of max length 4&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;HBufC* heapBuf = HBufC::NewL(4);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;// Copy in the contents of KFred&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;*heapBuf = KFred; // heapBuf now contains "Fred"&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;// Or, a more direct alternative:&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;HBufC* heapBuf = KFred().AllocL();&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;_LIT(KBert, "Bert");&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;TPtr ptr(heapBuf-&gt;Des()); // Modifiable TPtr over heapBuf data area&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;ptr = KBert(); // Copies "Bert" into heapBuf&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;delete heapBuf; // heapBuf deleted - ptr is now invalid&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;The heap descriptors can be created dynamically to the size required, but are not automatically resized when additional data storage is needed.  Instead, you must make sure the buffer has sufficient memory before calling a modification operation.  If necessary, you can reallocate the buffer, to grow it to the desired size, using the set of ReAllocL() methods.  These may potentially move the buffer from its previous memory location.  If there is insufficient memory, they will leave.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;_LIT(KFred, "Fred");&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;// Allocate a heap descriptor of max length 4&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;HBufC* heapBuf = KFred().AllocLC();&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;_LIT(KCyril, "Cyril");&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;TPtr ptr(heapBuf-&gt;Des()); // Modifiable TPtr over heapBuf data area&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;ptr = KCyril(); // This would panic because max length (4) is exceeded&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;// Instead, we need to do a reallocation&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;// Leave on cleanup stack in case the realloc fails and a leave occurs&lt;br /&gt;heapBuf = heapBuf-&gt;ReAllocL(5);&lt;br /&gt;&lt;br /&gt;// Realloc succeeded, but heapBuf pointer may have changed&lt;br /&gt;// We must update the pointer stored on the cleanup stack&lt;br /&gt;CleanupStack::Pop(); // Push it off&lt;br /&gt;// Push it back on again&lt;br /&gt;CleanupStack::PushL(heapBuf);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;// Since realloc may have changed the location in memory&lt;br /&gt;// we must also reset ptr&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;ptr.Set(heapBuf-&gt;Des());&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;ptr = KCyril(); // Copies "Cyril" into heapBuf&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;CleanupStack::PopAndDestroy(heapBuf); // heapBuf destroyed&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Moral of the story&lt;/span&gt;&lt;br /&gt;Heap descriptors can be created dynamically but are not automatically resized should they need to be extended.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111732190033486935?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111732190033486935/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111732190033486935' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111732190033486935'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111732190033486935'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/05/20-how-do-i-use-heap-based-buffer.html' title='20. How do I use heap-based buffer descriptors?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>10</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111731795308351067</id><published>2005-05-28T15:05:00.000-07:00</published><updated>2006-05-21T15:48:38.086-07:00</updated><title type='text'>19. How do I use stack-based buffer descriptors?</title><content type='html'>The stack-based buffer descriptor classes are &lt;span style="font-family:courier new;"&gt;TBufC&amp;lt;n&amp;gt; &lt;/span&gt;and &lt;span style="font-family:courier new;"&gt;TBuf&amp;lt;n&amp;gt;&lt;/span&gt;. They are useful for fixed-size or relatively small strings, say up to the length of a 256-character filename (i.e. where n &lt;=256). As I've previously described in &lt;a href="http://descriptors.blogspot.com/2005/05/6-large-stack-based-descriptors.html"&gt;&lt;i&gt;6. Large stack-based descriptors&lt;/i&gt;&lt;/a&gt; and in &lt;a href="http://descriptor-tips.blogspot.com/2005/05/tip-3-need-small-known-length.html"&gt;Tip 3&lt;/a&gt;, because they are stack-based, and stack space is limited on Symbian OS, if you need a larger buffer, you should use the heap (either by using the heap-based buffer descriptors, or having &lt;span style="font-family:courier new;"&gt;TBuf&lt;/span&gt; or &lt;span style="font-family:courier new;"&gt;TBufC&lt;/span&gt; as member variables of C classes). Being stack-based, these descriptors should also only be used when they have a lifetime that coincides with that of their creator.&lt;br /&gt;&lt;br /&gt;The &lt;span style="font-family:courier new;"&gt;TBuf&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;TBufC&lt;/span&gt; descriptors are somewhat equivalent to &lt;span style="font-family:courier new;"&gt;char[]&lt;/span&gt; in C, but benefit from internal overflow checks. As you've probably guessed by now, they may be constant (&lt;span style="font-family:courier new;"&gt;TBufC&lt;/span&gt;) or modifiable (&lt;span style="font-family:courier new;"&gt;TBuf&lt;/span&gt;).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;&lt;span style="font-family:courier new;"&gt;TBufC&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;The layout of the buffer descriptors is such that the string data forms part of the descriptor object itself, and follows the length word for &lt;span style="font-family:courier new;"&gt;TBufC&lt;/span&gt; and the maximum length word for &lt;span style="font-family:courier new;"&gt;TBuf&lt;/span&gt;. You can find a diagram in [&lt;a href="http://descriptors.blogspot.com/2006/05/references-to-other-descriptors.html"&gt;&lt;i&gt;reference 5&lt;/i&gt;&lt;/a&gt;].&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;TBufC&lt;/span&gt; is a thin template class which uses the &lt;span style="font-family:courier new;"&gt;TInt&lt;/span&gt; value to fix the size of the data area. The non-modifiable buffer class is used to hold constant string or binary data. It derives from &lt;span style="font-family:courier new;"&gt;TBufCBase&lt;/span&gt; (which derives from &lt;span style="font-family:courier new;"&gt;TDesC&lt;/span&gt;, and only exists as an inheritance convenience. It should not be used directly).  You can find more about thin templates from Chapter 19 of my book, Symbian OS Explained, more details of which are in the &lt;a style="font-style: italic;" href="http://descriptors.blogspot.com/2006/05/references-to-other-descriptors.html"&gt;References&lt;/a&gt; section.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;TBufC&lt;/span&gt; defines constructors that allow it to be created from a copy of any other descriptor or from a zero-terminated string. They can also be created empty and filled later. This may at first seem unintuitive for a constant buffer, but in fact, while the data itself is constant, the contents of the buffer may be replaced by calling the assignment operator of the class. The replacing data must not exceed the length specified when the buffer was created, or a panic will occur, in both debug and release modes.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;TBufC&lt;/span&gt; also has a &lt;span style="font-family:courier new;"&gt;Des()&lt;/span&gt; method which returns a modifiable pointer descriptor for the data represented by the buffer. So, while the contents cannot be altered directly by calling functions such as &lt;span style="font-family:courier new;"&gt;Format()&lt;/span&gt; or &lt;span style="font-family:courier new;"&gt;LowerCase()&lt;/span&gt; upon it, it is possible to change the data indirectly by creating a &lt;span style="font-family:courier new;"&gt;TPtr&lt;/span&gt; around the data in the buffer. When the modification occurs, the length of both the pointer descriptor and the constant buffer descriptor it refers to are changed. But remember, it cannot be extended because the descriptor classes do not provide memory management. So, don't call &lt;span style="font-family:courier new;"&gt;Append()&lt;/span&gt; on the &lt;span style="font-family:courier new;"&gt;TPtr&lt;/span&gt; unless you know there's sufficient space!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;_LIT(KFred, "Fred");&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;_LIT(KBert, "Bert");&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;TBufC&lt;4&gt; fredBuf(KFred); // Constructed from literal descriptor&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;TPtr ptr(FredBuf.Des()); // max length = 4&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;ptr = KBert; // fredBuf now containts "Bert"&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;_LIT(KCyril, "Cyril");&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;ptr = KCyril; // Panic! KCyril exceeds max length of ptr (=4)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;&lt;span style="font-family:courier new;"&gt;TBuf&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Like &lt;span style="font-family:courier new;"&gt;TBufC&lt;/span&gt;, the corresponding modifiable buffer class, &lt;span style="font-family:courier new;"&gt;TBuf&amp;lt;n&amp;gt;&lt;/span&gt;, is a thin template class, where &lt;span style="font-family:courier new;"&gt;n&lt;/span&gt; defines the maximum length of the descriptor data area. &lt;span style="font-family:courier new;"&gt;TBuf&lt;/span&gt; derives from &lt;span style="font-family:courier new;"&gt;TBufBase&lt;/span&gt;, which itself derives from &lt;span style="font-family:courier new;"&gt;TDes&lt;/span&gt;. &lt;span style="font-family:courier new;"&gt;TBuf&lt;/span&gt; thus inherits the full range of descriptor operations from &lt;span style="font-family:courier new;"&gt;TDes&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;TDesC&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Although the buffer is modifiable, as with all descriptors, memory management of the &lt;span style="font-family:courier new;"&gt;TBuf&lt;/span&gt; is your responsibility and it cannot be extended beyond the initial maximum length set on construction. If it needs to expand, you need to make sure that you either make it large enough at compile time (but not too large to waste valuable stack space) or use a descriptor which you can dynamically allocate at runtime. This means using an &lt;span style="font-family:courier new;"&gt;HBufC&lt;/span&gt; heap descriptor, described in &lt;a href="http://descriptors.blogspot.com/2005/05/20-how-do-i-use-heap-based-buffer.html"&gt;&lt;i&gt;20. How do I use heap-based buffer descriptors?&lt;/i&gt;&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111731795308351067?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111731795308351067/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111731795308351067' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111731795308351067'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111731795308351067'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/05/19-how-do-i-use-stack-based-buffer.html' title='19. How do I use stack-based buffer descriptors?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111730772006883827</id><published>2005-05-28T12:08:00.000-07:00</published><updated>2006-05-22T09:46:31.220-07:00</updated><title type='text'>18. How do I declare a TPtr or TPtr8 for definition later?</title><content type='html'>I want to initialise a &lt;span style="font-family:courier new;"&gt;TPtr&lt;/span&gt; later, but declare it now.  How do I do this?&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;TPtr8 myPtr(NULL, 0);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;or, for member data, in the constructor's initialization list:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;CMyClass::CMyClass() &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;: iPtr(NULL, 0)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;{}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To assign to it later, use &lt;span style="font-family:courier new;"&gt;Set()&lt;/span&gt; as described in &lt;a style="font-style: italic;" href="http://descriptors.blogspot.com/2005/05/16-what-does-tptrcset-do.html"&gt;16. What does TPtrC::Set() do?&lt;/a&gt;.  For example:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;myTPtr.Set(myHBufC-&gt;Des());&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;iPtr.Set(someExistingBuf);&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111730772006883827?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111730772006883827/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111730772006883827' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111730772006883827'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111730772006883827'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/05/18-how-do-i-declare-tptr-or-tptr8-for.html' title='18. How do I declare a TPtr or TPtr8 for definition later?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111904356941545597</id><published>2005-05-14T14:00:00.000-07:00</published><updated>2006-05-21T15:35:10.350-07:00</updated><title type='text'>17. What does TPtr::operator=() do?</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;The assignment operator, &lt;span style="font-family:courier new;"&gt;operator=()&lt;/span&gt;, &lt;span style="font-weight: bold; font-style: italic;"&gt;defined for modifiable pointers only&lt;/span&gt;, copies data into the memory already referenced by the pointer.&lt;br /&gt;&lt;br /&gt;If the length of the data to be copied exceeds the length available, the assignment will panic. &lt;span style="font-family:courier new;"&gt;TPtr &lt;/span&gt;also has a &lt;span style="font-family:courier new;"&gt;Set()&lt;/span&gt; method to change the descriptor to point at different data and you should be careful not to confuse them.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;To reiterate:&lt;br /&gt;&lt;/span&gt;As I described in &lt;a href="http://descriptors.blogspot.com/2005/05/16-what-does-tptrcset-do.html"&gt;&lt;i&gt;16. What does TPtrC::Set() do?&lt;/i&gt;&lt;/a&gt;, &lt;span style="font-family:courier new;"&gt;TPtr::Set()&lt;/span&gt; resets either a constant or modifiable pointer descriptor to point at a new data area (with corresponding changes to the length and maximum length members).&lt;br /&gt;&lt;br /&gt;The assignment operator on &lt;span style="font-family:courier new;"&gt;TPtr&lt;/span&gt; copies data into the existing descriptor area if it is large enough, or panics if it is not. It may modify the descriptor length but will not affect its maximum length.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111904356941545597?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111904356941545597/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111904356941545597' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111904356941545597'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111904356941545597'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/05/17-what-does-tptroperator-do.html' title='17. What does TPtr::operator=() do?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111610457081028730</id><published>2005-05-14T13:59:00.000-07:00</published><updated>2006-05-18T13:21:39.513-07:00</updated><title type='text'>16. What does TPtrC::Set() do?</title><content type='html'>Set() may be called on a constant or modifiable pointer descriptor to change what it points to, that is, to set it to reference different string data.&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;_LIT(KFred, "Fred");&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;_LIT(KBert, "Bert");&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;TPtrC fred(KFred); // contains 'Fred'&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;TPtrC bert(KBert); // contains 'Bert'&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;bert.Set(fred); // bert now contains 'Fred'&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111610457081028730?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111610457081028730/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111610457081028730' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111610457081028730'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111610457081028730'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/05/16-what-does-tptrcset-do.html' title='16. What does TPtrC::Set() do?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111610320588088329</id><published>2005-05-14T13:37:00.000-07:00</published><updated>2006-05-21T15:23:58.633-07:00</updated><title type='text'>15. What is the memory layout of pointer descriptors?  How much memory do they occupy besides the data itself?</title><content type='html'>Since pointer descriptors all derive from &lt;span style="font-family: courier new;"&gt;TDesC&lt;/span&gt; (either directly for constant pointer descriptors or from &lt;span style="font-family: courier new;"&gt;TDes&lt;/span&gt;, for modifiable descriptors), the first 4 bytes are used to store the current length of the descriptor data.&lt;br /&gt;&lt;br /&gt;In a constant pointer descriptor (&lt;span style="font-family: courier new;"&gt;TPtrC&lt;/span&gt;), a 4-byte pointer to the data follows the length word, thus the total size of the descriptor object is two words (8 bytes).&lt;br /&gt;&lt;br /&gt;In a modifiable pointer descriptor (&lt;span style="font-family: courier new;"&gt;TPtr&lt;/span&gt;) which derives from &lt;span style="font-family: courier new;"&gt;TDes&lt;/span&gt;, the maximum data length word follows the current length, which is then followed by the data pointer.  Thus, the descriptor object is three words in length (12 bytes).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You can find some diagrams which illustrate this in [&lt;a href="http://descriptors.blogspot.com/2006/05/references-to-other-descriptors.html"&gt;&lt;i&gt;reference 4&lt;/i&gt;&lt;/a&gt;].&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111610320588088329?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111610320588088329/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111610320588088329' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111610320588088329'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111610320588088329'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/05/15-what-is-memory-layout-of-pointer.html' title='15. What is the memory layout of pointer descriptors?  How much memory do they occupy besides the data itself?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111610203520950152</id><published>2005-05-14T13:18:00.000-07:00</published><updated>2006-05-18T13:20:56.766-07:00</updated><title type='text'>14. Do pointer descriptors own and manage the memory they point to?</title><content type='html'>No.  Absolutely not.&lt;br /&gt;&lt;br /&gt;The memory that holds the data referenced by a pointer descriptor is not owned by it, but will have been previously allocated.  Pointer descriptors are agnostic about where the memory they point to is actually stored (in ROM, on the heap or on the stack). &lt;br /&gt;&lt;br /&gt;The string data of a pointer descriptor is separate from the descriptor object itself and pointer descriptors themselves are usually stack-based, although they can be used on the heap, for example as a member variable of a CBase-derived class.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111610203520950152?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111610203520950152/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111610203520950152' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111610203520950152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111610203520950152'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/05/14-do-pointer-descriptors-own-and.html' title='14. Do pointer descriptors own and manage the memory they point to?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-12650648.post-111568151588292182</id><published>2005-05-09T16:27:00.000-07:00</published><updated>2006-05-21T15:17:08.163-07:00</updated><title type='text'>12. What is the layout of modifiable descriptors?</title><content type='html'>Modifiable descriptors all derive from the base class TDes, which itself is a subclass of TDesC.  TDes has an additional 4-byte member variable, which is used to store the maximum length of data currently allocated to the descriptor. &lt;br /&gt;&lt;br /&gt;TDes defines a range of methods for modifying string data.  Like the non-modifiable descriptors, all the manipulation is inherited by the derived classes, and works regardless of their type. The subclasses only implement specific methods for construction and copy assignment.&lt;br /&gt;&lt;br /&gt;Apart from the allocation methods of the heap buffer descriptors, no descriptor functions allocate any memory.  So any modification which extends the data of the descriptor, eg Append(), will check that there is sufficient memory available before proceeding.  The contents of the descriptor can shrink and expand at will, as long as the length does not exceed the maximum.  If the length of the descriptor contents is less than the maximum length, the end of the block of memory allocated to the descriptor is simply unused.&lt;br /&gt;&lt;br /&gt;Descriptor code uses assertion statements to ensure that the maximum length of the descriptor is sufficient, before proceeding.   The checks are made in both debug and release builds, and panic if an overflow would occur.  This avoids the hard-to-trace memory scribbles and buffer overflows typical of C style strings. &lt;br /&gt;&lt;br /&gt;(See also &lt;a href="http://descriptors.blogspot.com/2005/05/11-what-is-layout-of-non-modifable.html"&gt;&lt;i&gt;11. What is the layout of non-modifiable descriptors?&lt;/i&gt;&lt;/a&gt;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/12650648-111568151588292182?l=descriptors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://descriptors.blogspot.com/feeds/111568151588292182/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=12650648&amp;postID=111568151588292182' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111568151588292182'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/12650648/posts/default/111568151588292182'/><link rel='alternate' type='text/html' href='http://descriptors.blogspot.com/2005/05/12-what-is-layout-of-modifiable.html' title='12. What is the layout of modifiable descriptors?'/><author><name>Jo Stichbury</name><uri>http://www.blogger.com/profile/11641972941072027994</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09309832949275987157'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry></feed>