"herry" <[EMAIL PROTECTED]> wrote in message news:31856@palm-dev-forum...
>
> I wrote a C++ string class that overloads operator= and operator+. The
> problem is that doing things like
>
> String A = B + C + D + E + F + G;
>
> causes my application to become unstable and end up with "Fatal
Exception."
>
> I know that there is no bug in the code because my String class runs fine
on
> PC's compiled with Visual C++.
>
> Could it be possible that the App is running out of heap space? When
you
> do a "new char[x]" is this memory taken out from the local application
> heap, or is the space allocated in dynamic memory? ( like MemPtrNew() ?)
>
> How does one create an object that is located on the dynamic heap?
Clearly,
> MemPtrNew(sizeof(someobject)) will not cause the constructor for that
object
> to be called, nor its destructor.
It could be possible that you're running out of stack space, due to
temporary objects created to perform this operation.
String A = B + C + D + E + F + G;
is equivalent to
String t1 = String::operator +(B, C);
String t2 = String::operator +(t1, D);
String t3 = String::operator +(t2, E);
String t4 = String::operator +(t3, F);
String t5 = String::operator +(t4, G);
String A(t5);
CW Palm 6 would allocate five temporary String objects on the stack (which
is limited to 3.5K or less on many PalmOS devices). CW doesn't reuse stack
space for objects with non-conflicting lifetimes (a major shortcoming,
IMHO), so that stack space is eaten for entire life of the function,
including any functions it calls.
You could do much better in a situation like this to define an operator +=
then code
String A = B;
A += C; A += D; A += E; A += F; A += G;
which would have no extra temporary objects.
For the record, CW's implementation of new and delete call MemPtrNew and
MemPtrFree to manage the dynamic memory for the object.
--
Ben Combee
Veriprise Wireless <http://www.veriprise.com>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/