Basic use of Symbian string processing

Source: Internet
Author: User

The content is part of your Symbian Study Notes:

What are the string processing classes?

A:

Note that the strings on Symbian are called Descriptor and descriptors.
Tdesc and TDES
These two classes are abstract and cannot be instantiated. They are mostly used in function parameters.

Tbufc and tbuf

Tbufc = ilength + buffer (ttext)
Tbufc has a spoofing method des (), which returns a pointer pointing to modifiable content.
Tbuf = ilength + imaxlength + buffer (ttext)
It is generally used for temporary strings.

Tptrc and tptr

Unlike tbuf, tptr does not store content on its own, but stores a pointer to the execution content.
Tptrc = ilength + iptr
Similar to the relationship between tbufc and tbuf, tptr stores one more imaxlength than tptrc.

Hbufc

H indicates that heap is allocated to the heap memory and can be managed by clearing the stack.

When are these Descriptors (string classes) used?
A: tbuf is commonly used as a counterpoint. hbufc is used to read large texts.

Figure from Symbian OS explained

If tbufc <n> is assigned a string greater than N length, will it be truncated or panic?

A: User 11 panic will occur.

This panic is raised when any operation that moves or copies data to a 16-bit
Variant descriptor, causes the length of that descriptor to exceed its maximum
Length.

It may be caused by any of the copying, appending or formatting Member
Functions and, specifically, by the insert ()
,
Replace ()
, Fill ()
, Fillz ()
And
Zeroterminate ()
Descriptor member functions. It can also be caused
By the setlength ()
Function. See tdes16
.

Can I instantiate a tdesc?

A: No, because the tdesc constructor is private. However, you can use the copy constructor:
Tbuf <3> Buf (knulldesc );
Tdesc A (BUF );.

Use tbuf <508609> buf1 (ktry1); (508609 is an exact number. I tried it.) have I killed emulator ?!

What is the sizeof Size Rule of tbuf <n>?

A:
Tbuf <n> Should Be type & length (4) + max_length (4) + N x (1 byte or 2
Byte ),
1 or 2 bytes depend on whether tbuf8 is used or tbuf16. the first four digits are type & length, where 4 bits are allocated to type and can be stored 2 ^ 4 =
16 types
After trying, we found that:

N Sizeof Formula
0 8 4 + 4 + 0
1 12 4 + 4 + 1x2 = 10 align
2 12 4 + 4 + 2x2 = 12
3 16 4 + 4 + 3x2 = 14 align
8 24 4 + 4 + 8x2 = 24
10 28 4 + 4 + 10x2 = 28
20 48 4 + 4 + 20x2 = 48

It indicates that tbuf16 contains 4-byte alignment, and sizeof is a multiple of 4.

Is the name of the string processing class suffixed with C, and the meaning of it will also be squashed to clear the stack?

A: No. The meaning is that it cannot be modified, constant.

What is _ macro?

A: It is used to generate a constant character array variable of the type tlitc <n>.
For example: _ decrypt (khellodesc, "hello ");
Declare a const static tlitc <5> khellodesc;
Then assign it a "hello" string.
Note that you do not need to declare variables of the tlitc type when writing code. The _ struct Macro will do this for you.
Implementation Code:
# DEFINE _ aggregate (name, S) const static tlitc <sizeof (L # S)/2> name = {sizeof (L ## S)/2-1, l ## s}
Here,-1 is used to remove the ending/0, because the descriptor has a length and does not need the end symbol of a C-style string.

What does _ l do?

A: It is used to create a string, but according to symbian_ OS _basics_workbook, This is not recommended for low efficiency (generating temporary variables). We recommend using _ variable.

What should I pay attention to when using hbufc?

A:
Hbufc has the reallocl method, which can be re-allocated when the original allocated memory is not enough, but note that the pointer address will change after the re-allocation. If the stack is removed before
A pointer Mismatch Error occurs when popanddestroy (Tany *) is executed. If popanddestroy () is executed, a repeated memory release error occurs.
Solution:
You can use cleanupstack: Pop () to bring up the previous pointer before calling reallocl. Call pushl to push the new pointer to the cleanup stack after successfully allocating the memory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.