Symbian
Symbian OS Library

FAQ-0594 How do I use descriptors?

[Index][spacer] [Previous] [Next]



 

Classification: C++ Category: Base
Created: 04/17/97 Modified: 10/31/2001
Number: FAQ-0594
Platform: Not Applicable

Question:
I've been programming for years. I've programmed in C, C++, Pascal and even FORTRAN. I've used MFC. I understand C
strings. But how do I use descriptors?


Answer:
Descriptors take a bit of getting used to, and reading code which uses descriptors isn't sufficient preparation for writing code which uses descriptors.

Part of the problem is that everyone gets taught C++ with examples of "C strings that manage their own storage", but EPOC32 doesn't actually provide such a thing. There seem to be a million different flavours of descriptor and it's so hard to chose the right one. I believe it would be very helpful to have some sort of "flow chart" for choosing the right descriptor type. In the spirit of this database I offer the following starting questions (and then I get stuck!).
    1. Are you dealing with "characters" or is this strictly just sequences of bytes?

    => Sequences of bytes means that you must use the Txxx8 types, otherwise just use Txxx and let the system give you Txxx8 for ASCII builds and Txxx16 for UNICODE builds.

    2. Do you need to modify the data or will you just be appending to it?

    => If the data isn't going to be tampered with, except for appending, then use TxxxC

    3. Is the data to be stored in the descriptor, or do you have the data storage elsewhere?

    => TBuf descriptors own the storage for the data. TPtr descriptors hold a pointer to the actual data which is owned by someone else.

    4. Do you know in advance how much space your data will require?

    => No? Use an HBufC and be careful about appending or, if your data might be really long, use a CBufBase-derived buffer class (eg CBufSeg) instead.