1. What are Literal LDescriptors?
Literal descriptors are constant descriptors which are compiled into ROM because their contents does not ever change.
There are two types of literal descriptor
1. _LIT - Most efficient and preffered.
2. _L - which is now deprecated in all but test code.
The macros are defined in the Symbian OS header file e32def.h and create an object of type TLitC16 or TLitC8 (defined in e32des.h). These classes do not derive from TDesC8 or TDesC16 but have the same binary layout as TBufC8 or TBufC16. This means that the literal object can be used wherever TDesC is used.
8-bit for non-Unicode strings: _LIT8(KNullDesC8,"TEXT");
16-bit for Unicode strings: _LIT16(KNullDesC16,"TEXT");
Literal descriptors are constant descriptors which are compiled into ROM because their contents does not ever change.
There are two types of literal descriptor
1. _LIT - Most efficient and preffered.
2. _L - which is now deprecated in all but test code.
The macros are defined in the Symbian OS header file e32def.h and create an object of type TLitC16 or TLitC8 (defined in e32des.h). These classes do not derive from TDesC8 or TDesC16 but have the same binary layout as TBufC8 or TBufC16. This means that the literal object can be used wherever TDesC is used.
8-bit for non-Unicode strings: _LIT8(KNullDesC8,"TEXT");
16-bit for Unicode strings: _LIT16(KNullDesC16,"TEXT");
2. Why is the _L literal descriptor macro deprecated?
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.
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.
3. How to use Descriptors as parameters?
TDesC or TDes should be used as arguments to function, this allows descriptors to be passed with out restricting the caller of the function to use a specific type.
void Function(const TDesC& aReadOnlyDescriptor, TDes& aReadWriteDescriptor);
here the caller can call the function with anything which is derived from TDesC & TDes. For Ex it can be HBuf, TBuf ot Tptr.
0 comments:
Post a Comment