Probably the number one question on the mind of any new Symbian OS developer (and some seasoned ones too!) is descriptors, why, how, where, which one… the list continues. So here’s list of definitive resources on descriptors on the way, which IMO should answer all your questions. Finally, there’s my rules of thumb on using descriptors, which you can find at the end of the article.
- Descriptors: Excellent presentation from Symbian on descriptors, with detailed discussion on the internal structure of descriptors, their place in C++ code and most importantly, which ones to use in which circumstances.
- Descriptors FAQ: Excellent FAQ on descriptors maintained by Jo Stichbury that complements the presentation above really well.
- Using Descriptors: From the latest Symbian OS documentation. Pretty useful.
And now for the impatient! Basic rules of thumb on descriptor usage. Remember these are just rules of thumb and not a definitive guide.
- I need a temporary (stack based) string and I know the possible max length, like printing out a message. What should I use? Use a TBuf.
- I need to have a class member, e.g. contact name, whose max size is known before hand. Use a TBuf.
- Same situation as before, but I have many string member variables.
Use a TBufC in that case. TBufC is a bit more (4 bytes) RAM efficient than TBuf. However, remember, you can’t directly manipulate a TBufC and need to call Des (expensive?) on it to get a modifiable pointer, or simply use the assignment operator to replace the whole content of the TBufC.
- I need a dynamically allocated string on the fly or as a member variable (max length not anticipated). Use RBuf.
That’s it, not much to it, is there? The keen reader will notice that I have failed to mention a particular class whose name begins with H. Well, I say its time to bury it behind RBuf, once and for all.