Descriptor in Symbian

xiaoxiao2021-03-06  74

I haven't written blog for a long time, I have been developed on Symbian, which has been summarized on Symbian strings. The format is not arranged, and it is more confusing. It is too lazy to finish. TDESC itself contains only two member variables, Type and Length. TYPE is used to avoid virtual functions, and lonth represents the length of the object. This also determines that Symbian's Descriptor is a closed system, that is, developers unable to extend from the Descriptor Class provided by the system to extend their functions.

The main member functions are: Tint Length () const; const tuint8 * ptr () const; returns an unmodently modified pointer.

Due to the modification, TDES thus increasing a maxlength and returns the maximum length capable of accommodating. Trouble is that it does not provide a function that returns a writable pointer. WPTR is protected.

Therefore, TBUF has an IMAXLENGTH member due to indirectly from it. And TBUFC, HBUFC is not.

These two classes are abstract classes. But unfortunately, there is no copy constructor that automatically generated by the compiler in the Symbian source code. Therefore, the following code and legal. EXTERN TPTR PTR; TDESC DES = PTR;

TPTRC is derived from TDESC, a member variable pointer similar to const char ×, TPTR is derived from TDES, and there is also a char * member variable PTR pointer attention; TPTRC and TPTR itself do not "have" memory, but only point to one Has been allocated. And the destructor of TPTRC / TPTR is reasonable, and it is not free.

Point to the memory. In addition, when the function provided by TPTR / TDES is modified, the actual memory is modified. In addition, even the TPTR itself of this pointer member variable IPTR may not necessarily point to the first address of the actual memory, the only way to guarantee the first address is called

The PTR () function in TDESC. For example, if you actually refer to 4 byte locations in front of TPTR by calling TBUFC :: DES ()

SIMULATOR in Simulator).

If TPTR is from the DES () function of TBUFC / HBUFC, then the function in TDES affects Ilength, Ilength in TBUFC / HBUFC is also changed.

changed.

If the TPTR is obtained by constructing, because the memory pointing to the TPTR can be any writable data, it only affects its length. In this way, there are actually two types of TPTR. When a length change is changed, it is necessary to simultaneously set the length of TBUFC / HBUFC, and another is not. It is estimated to distinguish between ITYPE inside TDESC.

TBUFC is derived from TDESC, there is a member variable similar to const char []. There is basically no need to exist. After all, we allocate memory in the stack, basically, for "writable", and TDESC does not provide any "write" function. Fortunately, it also provides a des () function to get a writable TPTR / TDES object. But still trouble.

TBUF is derived from TDES, there is a member variable similar to CHAR []. However, its parent class TDES does not have a way to return a writable pointer. There is a WPTR () or protected. Sigh!

HBUFC is derived from TDESC, can't do it without a HBUF class. A des () function returns a writable TPTR object.

In addition, since Descriptor can represent both characters, it can also represent binary data. Therefore, an additional '/ 0' location is not retained when the default memory is allocated. For example, TBUF <3> BUF; then the size of this buf is indeed only 3. TLITC is prepared for String, so the '/ 0' characters have been included in CHAR [] using the SizeOf operator. But the length of the TDESC of Cast may still be Strlen

_LIT (KSTR, "Hello"); TDESC DESC = KSTR; INT LEN = desc.length (); // Check The Length

Hbufc8 * hbuf1 = hbufc8 :: newlc (1); hbufc8 * hbuf2 = hbufc8 :: newlc (4); hbufc8 * hbuf3 = hbufc8 :: newlc (8);

TDES DES1 = HBUF1.DES (); des1 = hbuf2.des (); des2 = hbuf3.des ();

Cleanupstack :: PopandDestroy (3); // hbufc8

TDES / TDESC is an abstraction, TPTR / TPTRC is auxiliary, TBUF / HBUFC / TBUFC is a place for specific data saving.

Check Symbian's memory leaks in the VC: F5 until the program PANIC, then find similar THREAD PANIC Alloc: F90B380 in Output WINDOW, find the corresponding memory address. Restart the Emulator and check the content corresponding to this address. You can check when you quit, or you can set the "DATA" breakpoint when you start.

DEScripOR in Symbian does not assign each other. For example, TPTR PTR = BUF.PTR (0); PTR = BUF.PTR (1); // PTR may not be modified, resulting in undesirable behavior. This place needs to be extremely paying attention to, all writable Descriptor, such as TBUFC, TBUF, TPTR, HBUFC, SYMBIAN overloads Operator = () function, actual

The semantics are not similar to assignment statements you may want, but copy the contents of the right value to the memory referred to by the left value Descriptor.

For example: TBUF8 <5> BUF1 (_L8 ("Hello")); TBUFC8 <5> BUF2 (_L8 ("World")); TPTR8 PTR ((Tuint8 *) buf1.ptr (), 5, 5); PTR = Buf2.des ();

The last sentence may, it is possible to make PTR point to BUF2, but actually change to the COPY assignment statement between buffers, the content of BUF2 is copied to PTR.

In the memory, the contents of BUF1 and BUF2 after run are World.

At the same time, the copy constructor of TPTR is different from the meaning of the ASIGNMENT operator. Extern TPTR B; TPTR A = B; // Call a copy constructor, A, B point to the same piece of buffer

TPTR A; // Compiling errors, no default constructor. Memory A = B must be allocated; // In the memory referred to in the contents of the B.

Strings in Symbian can basically be viewed in two eyes:

Const and non-Const, read-only and writable. Unicode and non-Unicode, namely 8bit and 16bit characters.

Therefore, it is assumed that a class TPTR8 is then added to C, and TPTRC8 represents the const version, and the 8 changes to 16 represents the Unicode version. TPTR is used by TypeDef to TPTR16 in the case of Unicode definition, otherwise TPTR8. Symbian strings always use Unicode.

Symbian uses Descriptor to represent a paragraph, which can be either in memory, or in a read-only ROM, can represent both strings or two

Billing data, therefore does not rely on '/ 0' characters, even at all, there is no '/ 0' character.

All Descriptor's base class is TDESC, which is actually an abstract class, in the Symbian's header file, all constructor's constructor is protected. because

You can't create TDESC, which will never (you should say that you should not) appear as follows: TDesc DES. But Symbian may neglect, and the comparison procedure is easy to make mistakes, it does not shield the copy constructor generated by C automatically. So the following statement does not have any compile warning: extern tptrc ptr; // tptrc is TDESC's derived class TDESC DES = PTR; // Call the default copy constructor, causing SLICE cutting foo (des); // Call a function, need Const TDESC & parameters, since the data has been cut, the result cannot be expected.

It is mainly used for function parameters, as a function parameter, not const tdesc & des, is const tdesc × des, which represents a read-only data, there are

According to Members Ilength, the length of the memory is indicated.

The following is the data member definition of TDESC: UNSIGNED INT ILENGTH: 28; Unsigned Int ITYPE: 4;

It can be seen that the maximum memory length representative of Descriptor can be 0x0fffffff, the remaining 4bit, iType represents the type of party.

Among them, TDESC has an important member function: public: const tuint * ptr () const; returns a pointer to this segment data. Generally, this should be defined as a pure virtual function, which is implemented by derived class.

In order to avoid overhead brought about by virtual functions, Symbian uses iTYPE to represent the specific type of party class. It's hard to imagine that TDESC can get the number of specific classes according to ITYPE

A head address.

All member functions of TDESC are const modifications, that is, any function does not modify the THIS pointer.

TDESC is actually a typedef, corresponding to Unicode's version, it is defined as tdesc16, non-Unicode is TDESC8, if you represent binary data, you can display

Show TDESC8.

TDES represents a writable data area, before, all Descriptor is derived from TDESC, TDES is no exception. Added a data member, protected: Tint Imaxlength;

Indicates the maximum effective length of the segment area, because TDES is not constant, can therefore be written. IMAXLENGTH prevents off-bounds from accessing. This class is also an abstract class that cannot be directly constructed.

A basic principle is that the read-only Descriptor is always derived from TDESC directly or indirectly without derived from TDES. The writable Descriptor is always derived from TDES directly or indirectly. Of course, since TDES's base class is TDESC, it is also derived from TDESC. TPTRC represents a read-only memory that is derived from TDESC. Initialized by a pointer to read-only data and the length of the segment data. Added a member variable: protected: const twtr; for example: const char * psz = "hello"; TPTRC8 PTR (PSZ, 5); // PTR points to PSZ, length 5. TPTRC8 PTR (PSZ 1, 2); // PTR points to 'E' to 'L', length is two.

TPTR represents a section of memory that is derived from TDES. Initialized by a pointer to the writeable data and the length of the segment data. Added a member variable: protected: tuint * iptr;

Example: char psz [] = "hello"; TPTR8 PTR (PSZ, 5); // PTR points to PSZ, length 5. TPTR8 PTR (PSZ 1, 2); // PTR points to 'E' to 'L', the length is two.

TPTR does not provide additional functions to manipulate, modify data, is provided by the base class TDES. For example; ptr.lowercase (); // lowercase conversion

TPTR and TPTRC do not really "owns" data, they just "point" this segment data, so the monographic function is naturally not free to drop this memory.

The above char psz [] = "Hello"; in Symbian, TBUF is generally defined. TBUF is a template class that the unique template parameter is the size of the data. After simplification, it is defined as follows:

Template Class TBUF8: Public TDES {Protected: Tuint8 Ibuf [S];

So if we define the "Hello" string above in your stack, you can follow:

/ / Since the TBUF does not provide a suitable constructor suitable for const char ×, we need to convert Const CHAR × // to const unsigned char *. Sigh! TBUF8 <5> BUF (Const Tuint8 *) "Hello");

Then we use the functions provided by TDES: BUF [0] = 'h'; // "Hello" buf.Lowercase (), etc. // "Hello"

There is also a corresponding TBUFC, providing a read-only version, derived from TDESC, as I see, basically care TBUF has a matching const class, which is not used. Dozens of Examples in Nokia Series 2.0 SDK, no one is using it. I don't want to use it. :) It is like you use the following statement: const char Hello []; you assign a memory in your stack, type Const Char. Unless you initialize it, you will only find trouble using const.

The last one is allocated in the heap, for example in C, we are generally as follows: char * psz = (char *) Malloc (20); free (PSZ); in Symbian, a HBUFC class is provided, pay attention to the last belt C is always directly / indirect from TDESC, and there is no relationship with TDES. So I can't use only the read-only member functions provided in the base class TDESC? The following is the definition of HBUFC: Class Hbufc8: public tdesc8 {public: import_c static hbufc8 * new (Tint Amaxlength); import_c tptr8 des (); private: Ttext8 Ibuf [1];};

Note IBUF [1] This method is often used in C to define a variable size structure. The front mentioned that HBUFC8 is derived from TDESC8, so it can only use the "read-only" member function provided by TDESC, but fortunately it also provides a des () function to return a TPTR8.

Pointer, since TPTR is inherited by TDES, so we can modify its content through TPTR. Sigh!

Looking forward to HBUF CLASS? Sorry, Symbian is not available. Since then. Example: HBUFC8 * PBUF = HBUFC8 :: New (100); // Equivalent to const char * psz = (const char *) malloc (100); delete pbuf; // is equivalent to Free (PSZ);

Pay attention to const char *, sigh! The pointer returned after the allocation is constrained, then what is the only memory of a read-only memory?

So if you want to do something proper, you must call the HBUFC's des () function to get a writeable TPTR object.

HBUFC8 * PBUF = HBUFC8 :: New (100); // Equivalent to const char * psz = (const char *) malloc (100); TPTR8 PTR = PBUF-> DES (); // Similar to char * p = (char *) PSZ; Ok, it is finally written. PTR [0] = 'h'; // * p = 'h'; call the function PTR.setlength in TDES; // p [1] = '/ 0'; call the function in TDES Delete PBUF; // Is equivalent to Free (PSZ);

I don't know what reason why Symbian defines an HBUFC instead of HBUF. Is it estimated to save data members in a TDES? However, from the "const" HBUFC call DES () function to "non-const" TPTR, this extra imaxlength, I don't know how Symbian is implemented? ^ _ ^, Originally calling Static Tint User :: Alloclen (const tany * acell) function.

转载请注明原文地址:https://www.9cbs.com/read-87835.html

New Post(0)