First, strengthen the impression
Before learning a descriptor, you first need to understand the role of the descriptor in Symbian. In Symbian, there is no class dedicated to handling strings, which regards strings and binary buffers as the same class of data, with a set of specialized classes to manage, and the class diagram hierarchy of this class is shown in the following illustration:
Figure I. Hierarchical relationship of Descriptor classes
The class shown above is collectively referred to as "descriptor", and Symbian uses "descriptors" to manage strings, where Tdesc, Tdes, and tbufcbase are abstract classes.
Let's start with a simple example to enhance our understanding of the descriptor. If we were to have a string "NEWLC", we would like to use variable storage, in the C language we could write with the following code:
char[] c = “NewLC”;
const char* c = “NewLC”;
and in Symbian C + +, should we use the above descriptor to store it?
The answer is: You can use any descriptor to store! We do not give the code, first show you how to use a different descriptor to store the string in memory in the form of:
Figure Two. The position of the descriptor object and the data in memory
Ii. Understanding of concepts
1, according to the descriptor data storage location for classification (figure II):
Stack descriptors tbuf and TBUFC: The data is present as part of the descriptor object, and the descriptor object is stored in the stack of the program, like an array of characters (char[] in C language).
Heap Descriptor HBUFC: The data is present as part of the descriptor object, and the descriptor object is stored in the heap, as is commonly used in C-language (char*) malloc (length+1) in cases where the length cannot be determined beforehand. Because it is allocated on the heap, it is always used through hbufc* instead of directly defining the HBUFC object.
The pointer descriptor tptr and TPTRC: The descriptor object is stored separately from the actual data it represents, and the descriptor object is stored on the stack, as in the meaning of "pointers", the data that the pointer descriptor points to can be data in the stack or data in the heap. Tptrc and tptr are somewhat similar to the char* in C, but because descriptors themselves contain length information, they no longer need to scan the trailing null character (' ") or allocate space for it.
2. Modifiable descriptors and non-modifiable descriptors:
As you can see, in the Descriptor class, some classes end with "C", which represents a "read-only descriptor", that is, the data that the descriptor has when it is defined or the data that it points to, and the descriptor does not provide a modified method. Therefore, it is recommended that you declare modifiable descriptors and immutable descriptors using the following methods:
const TDesC& str;
TDesC& str;
As you can see from figure one, the base class Tdesc does not provide a function to modify the content, while the inherited from Tdesc class Tdes provides functions for modifying the content.
3, the width of the descriptor
All of these descriptors can specify the data scale: TDES8, TDES16, TDesC8, TDesC16, TBuf8, TBUF16, etc.
Here 8 indicates that the data for the descriptor processing is 8bit, while 16 represents 16bit data. Generally, you just use the generic form (Tdes, Tdesc,... To represent the text data and use the 8bit version (TDESC8, etc.) to represent the contents of the binary.