Wednesday, May 04, 2005

2. Why use descriptors?

Can I use standard C arrays to store my text and binary data, and the C string library to manipulate them, like I have always done?

Should I use standard C arrays and the C string library for Symbian OS programming?

Why not?
Standard C arrays are unsafe. Why? Because they have no concept of how big they are. Null-terminated strings are clunky and inefficient. What’s more, if you want to write past the end of the allocated space of a standard C string, nothing is going to stop you. This leads to all kinds of mayhem, such as data corruption

An API I want to use requires descriptors, but I’ve used C strings. How do I convert between them?
Quite. Just about every Symbian OS C++ API you come across will use descriptors for transferring text and binary data somewhere, so if you’ve used C strings, you are going to have a problem using these APIs. You’ll have to do the conversion every time you want to use an API call requiring a descriptor, which is inefficient. So you might as well keep reading, and learn how to use descriptors correctly.

As described in Symbian OS Explained, descriptors have been optimised to be memory efficient on Symbian OS. It's not advisable to 'roll your own' string class which wraps the descriptor classes, because it's unlikely you'll get anything more lightweight.

And in the time you take to write the wrapper classes, you'll learn so much about descriptor classes that you'll be able to use them directly anyway :o)
"such as data corruption" should be "such as data corruption." (with a dot).
Nice catch anonymous. I'm afraid I'm a bit haphazard with my full stops so you'll find a few more of those throughout the blog. Please don't bother reporting them all though - unless I have overwhelming evidence that their absence is causing people more problems than descriptors themselves, I won't be fixing them.
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?

WWW Descriptors FAQ