Saturday, August 02, 2008

How do I create a small, stack-based descriptor?

If it needs to be modifiable, use a TBuf.
If it's constant, use a TBufC. You'll need to specify the size of stack space allocated for the descriptor's data.

Here‚is an example:

_LIT(KFred, ‚"My sting"); // A string literal, these will be described later
TBufC<8> constantFred(KFred);

In reality, you probably wouldn't do this for a non-modifiable descriptor, since you can use the literal, KFred directly by calling the operator() function. That is, instead of creating constantFred, you could just call KFred().

However, this approach is still useful for modifiable descriptors, for example, for logging purposes:

_LIT8(KError, "RunError: %d");
TBuf8<35> errorBuf;
errorBuf.Format(KError, aError);

further reading

No comments:

stats counter