You have to use MemHandleLock to lock the handles to get access to the
pointers. You can not use a handle to manipulate the data directly. A handle
"points" to a movable chunk of memory. You have to lock it down in order to
get a pointer into the memory allocated for that handle. When you're done
temporarily accessing the data, you need to unlock the pointer/handle to
allow the memory chunk to move again.
-----Original Message-----
From: Philip J. Matheson <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Thursday, May 06, 1999 2:00 PM
Subject: Re: Wicked Confused about memory (Part Duh!)
Here's a little snippet from the Palm Companion Doc..
-->> Don�t access globals or hardware directly
ok.. I'm not really trying to access globals, but everything I try to do
with
my data structures gives me a "Trying to write/read from low memory area"..
how do I not do this? How do I go about accessing these indirectly? I seem
to
be missing something very importent because I cannot store and pass around
data without getting this error. The only data I can deal with is DB
stuff..
but I would like to manipulate data before I put it in the database. Heres
and
example:
static void DataBank(VoidHand* BuffHandle, VoidHand* DynHandle, VoidHand
*StatHandle)
{
static VoidHand Buff;
static VoidHand Dyn;
static VoidHand Stat;
Buff = MemHandleNew(sizeof(MovementRecord)+1);
Dyn = MemHandleNew(sizeof(DynamicRecordingInfo)+1);
Stat = MemHandleNew(sizeof(StaticRecordingInfo)+1);
*BuffHandle = Buff;
*DynHandle = Dyn;
*StatHandle = Stat;
}
After trying numerous other approaches with global variables. I decided to
create this function.. My hope is that the memory allocated here will be
static and not in "low memory" so that any time I need a handle to these
chunks I can just call this function and get a pointer to the handle. I
still
get the low memory err. What am I missing? It seems that no matter where I
call MemHandleNew I can not use that memory..
Thank You,
Philip J.
Gabe Dalbec wrote:
> In your code snip below, it seems you are unlocking the memory
> handle before you are done using it. You can't call MemHandleUnlock
> until you won't be using the locked location. So move the MemHandleUnlock
> to right before the return. Or use the FldGetTextPtr(fld) as the string
> to pass to checkDBName rather than LCurrentStatPtr->NameString.
>
> -Gabe
> Palm Creations
>
> static Boolean DatabaseOkButtonHook(void)
> {
> StaticRecordingInfo *LCurrentStatPtr;
> FieldPtr fld = GetObjectPtr(databaseNameStringField);
>
> gCurrentStatHand = MemHandleNew(sizeof (StaticRecordingInfo));
> LCurrentStatPtr = MemHandleLock(gCurrentStatHand);
>
> //here we're copying the new database name into memory
> if (FldGetTextPtr(fld) != NULL)
> {
> StrCopy(LCurrentStatPtr->NameString, FldGetTextPtr(fld));
> }
> MemHandleUnlock(gCurrentStatHand);
>
> if ( checkDBName(LCurrentStatPtr->NameString) )
> {
> FrmGotoForm(RecordForm);
> }
> else
> {
> FrmAlert(DbnameAlert);
> }
> return 0;
> }