And the disadvantages are not so obvious. The example you gave is not very
different from:

static void doSomething (char* final)
{
     char myString[20], aux[10];
     strcpy (aux, "Testing");
     strcpy (mystring, " string classes");
     strcpy (final, aux);
     strcat (final, mystring);
}

However, your version has a lot of hidden inefficiencies. First three string
constructors are called. Second the initial states of those strings -- carefully
and lovingly set up in their constructors -- is immediately wiped out with the
three subsequent assignment. Third, there is a temporary String created just to
hold the intermediate result of "aux + mystring". Fourth, there is the
assignment of "final" to the String object receiving the result of
doSomething(). Fifth, four or five String objects have to be deleted. Finally,
there are all of the hidden memory allocations associated with creating and
manipulating several String objects.

Perhaps one might scoff at these costs, saying that they are small compared to
the benefits of being able to use the + operator on strings. However:

* The Palm OS environment is very small. There's not much memory, and there's
not much processing power. You can't afford to be extravagent to any degree.

* I actually have some relevent experience in this area. I worked on the Pink
project at Taligent for several years. For those who don't remember, this was a
project to create a totally new, object-oriented operating system written in
C++. It never made it to market. One of the reasons was precisely because of
these hidden costs. It was way too easy to overcome the OS and the hardware. We
were easily crippling the biggest, baddest, fastest, most expensive desktop
hardware available at the time. And the reason for that was that the
seductiveness of C++ allowed us to fall into the trap of writing bloated
software. Looking at the code, it looked just fine, just like "string1 +
string2" looks fine. But under the surface, a LOT is going on.

Anyway, that's just my opinion, I could be wrong.

-- Keith






"Martin Krohn" <[EMAIL PROTECTED]> on 09/23/99 06:47:35 AM

Please respond to [EMAIL PROTECTED]

Sent by:  "Martin Krohn" <[EMAIL PROTECTED]>


To:   [EMAIL PROTECTED]
cc:    (Keith Rollin/HQ/3Com)
Subject:  Re: C++ SDK wanted!




Benefits of C++:
Imagine you can write this:

#include <StringLibrary.hpp>

static String doSomething()
{
String mystring, aux, final;
int i;
    aux = "Testing ";
    mystring = " string classes";
    final = aux + mystring;
    return final;
}

This is posible by writing a String class and overloading the "+" operator.
Benefits are obvious.


Reply via email to