George,

How HUGE is your global structure?  You should never create nor reference
globals from within the PalmMain function.  You should also keep your use of
globals to a minimum.  But any globals you do use in your app can be
created/initialized in your AppStart() function.

MemPtrNew allocates non-movable memory, I believe you can do it like so:

UInt32  *myVar
myVar = (*UInt32) MemPtrNew(sizeof(UInt32));    // allocates a UInt32 on the
dynamic heap
*myVar = 1;        // set its value
//free the memory
MemPtrFree(myVar);

// note, because this is non moval memory, you should not keep it around
long... if you need to keep something around, try using MemHandleNew,
MemHandleLock and MemHandleFree.  Its all in the palm OS reference guide.


"George" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello,
>
> Since I'm a Palm OS newbie, I need some help.  I'm debugging an
applicaiton
> using the Emulator and found out that the application sometimes gets
"memory
> leaks" error.
>
> Ben Combee also suggested that I should use "MemPtrNew" to decrease my
stack
> size in my previous thread.
>
> So, I've decided I should take a serious look at using "MemPtrNew" and
> "MemPtrFree" to make the application more efficient.
>
> However, I don't know how to use them.
>
> This is the existing code in my Pilot Main:
>
> UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
> {
>     ContextType context;
>     UInt16  error;
>     context.hasGlobals = launchFlags & sysAppLaunchFlagNewGlobals;
>
>     if (cmd == sysAppLaunchCmdNormalLaunch)
>     {   globalContext = &context;
>         error = AppStart(&context);
>         if (error) return error;
>         FrmGotoForm(ID_FORM_LIST);
>         EventLoop();
>         AppStop(&context);
>         return 0;
>     }
>     else if .... (codes snipped...)
>
> I use ContextType to store Global variables and it's huge.  That's the
> problem.  I need to free up the resources when ContextType is not used.  I
> just don't quite understand how to use MemPtrNew to free the memory.
>
> Thanks for your help in advance.
>
> George.
>
>
>



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

Reply via email to