Hi!

I am surprised Ben didn't direct you to his own web-page which explains this in even 
more detail:
http://www.palmoswerks.com/stories/storyReader$15
I have personally used essentially the alternative solution that is described on that 
page, which has the advantage that I can turn
all exception related compiler options off. This saves quite a bit on the code size.
My implementation can be found in http://www.tilo-christ.de/razor/Razor.zip in the 
file CustomNew.h.

Cheers,
Tilo

Ben Combee schrieb:

> "Steve Branin" <[EMAIL PROTECTED]> wrote in message
> news:69037@palm-dev-forum...
> >
> > Hi all,
> >
> > I have searched the archives extensively and I can't find any posts
> that
> > relate to my problem so I'll ask it here and hope that this isn't a
> frequent
> > topic here.  Here goes.
> >
> > Typically in C++ when I want to create an instance of an object I do
> > something like this:
> >
> > MyClass* pMyObject = NULL;
> > pMyObject = new MyClass();
> > if (pMyObject)
> > {
> >      do something
> > }
> >
> > and this is sufficient to verify that enough heap space was available
> to
> > successfully create the object.  However, when I do this in PalmOS and
> there
> > is not enough memory my application exits on the "new" line and never
> makes
> > it to the check.  What should I be doing to protect myself from an out
> of
> > memory condition?  I found tons of articles about memory management
> but none
> > that answered my question.  Code snippets would be most helpful.
>
> You should use the nothrow version of new.
>
> #include <new>
> ...
> MyClass* pMyObject = NULL;
>
> pMyObject = new (std::nothrow) MyClass();
> if (pMyObject)
> {
>      do something
> }
>
> This is the standard C++ way of saying that you want to get new memory,
> but you don't want an exception thrown if there is an error.
>
> If you're using CodeWarrior, you'll need to add the proper MSL access
> path to your project.  In CW Palm 8, this is "{Compiler}(MSL for Palm
> OS)".  In previous versions, you can add "{Compiler}MSL".
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe, please see 
>http://www.palmos.com/dev/tech/support/forums/


-- 
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