Jaime Villela wrote:
> 
> Is there any benefit to "rolling my own" constructor as opposed to just
> creating a C++ class and using the default "new" method?

MemPtrNew() will only allocate the memory for you.  It won't call
constructors for you like operator new will.  

If the objects you are creating are of a class which inherits from one
or more other classes, keep in mind that C++'s new and constructor
mechanisms will also ensure that parent class constructors are also
called where appropriate, and will call constructors for each element in
object arrays for you.  These things are possible to do yourself, but
error-prone to keep in synch as an object hierarchy evolves.

Another nit which may or may not apply to your chosen C++ environment is
that operator new is supposed to throw an exception by default on
out-of-memory error, whereas MemPtrNew() returns 0.  If you like the new
Standard C++ behavior and your C++ environment supports it, you will of
course want to use operator new for all memory allocations.

In general, use MemPtrNew() in C++ Palm OS programs only where you would
use malloc() on other platforms.
--
= The Palm OS Programmer's FAQ: http://tangentsoft.net/palmfaq/
=
= ICBM Address: 36.8274040 N, 108.0204086 W, alt. 1714m

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to