Literals provide a simple method of defining strings in a program. They can be defined and used as follows:
_LIT(KMyName, “Helen”);
TBuf<KMaxItemLength> myName;
myName.Append(KMaxItemLength);
Literals are easily changed if they are situated at the top of a .cpp file, just like macro definitions. The predecessor to _LIT was _L; you may see it being used as:
myName.Append(_L(“Helen”));
_L can still be used in test programs (non-release versions) where clarity is more important than efficiency but it has now been deprecated as _LIT is more efficient. The string supplied to _LIT is stored once per unit of compilation (.cpp file) unlike the string supplied to _L, which is inserted in the code each time it is used. Therefore _LIT consumes less memory if the string is used more than once and its use is encouraged by Symbian in creating memory-efficient applications.

Recent Comments