One of the beauties (and horrors) of C is that it is not strongly typed.
Both MemHandle and MemPtr are 32-bit objects.  Thus you can, SOMETIMES, pass
in one in place of the other.

?? When ?? you ask?

Well, basically only in two cases:
(1) the function your giving it to doesn't actually use it, just saves it
for you; or
(2) the function your giving it to is smart enough to know the difference.

FrmSetGadgetData lies in class (1), as do some of the Palm APIs.  As a (big)
clue that this is so, note that the function is not called FrmSetGadgetPtr.

Note that the only functions likely to lie in class (2) are those that your
write yourself.

Of course, when you use the gadget data, you durn well better know what sort
of beastie it be...

As to when to use handles vs. pointers, one could write a (small) book.
Basically use pointers for short-term access (lie when a form or control or,
perhaps, an app) is up but use handles for long-term access.  Handles take
more overhead but allow the system more flexibility in its memory management
chores.  

The OS needs to move memory around when lots and lots of memory is requested
of it.  Bear in mind that it is (likely) not just your application consuming
resources on that pesky little device.  Your (oh so noble) user may have
gone and downloaded the memory stressing application from hell.  Of course,
when your application is up, the other guys aren't (usually) doing too much
(other than beams, and finds, and alarms, and, and, and,...), so you can
(and probably should) use pointers most of the time.  But there are users
out there who will chew up as much available resources as they possibly can.

-bob mckenzie

-----Original Message-----
From: Brian Smith [mailto:[EMAIL PROTECTED]]
Sent: Monday, June 04, 2001 10:08 AM
To: Palm Developer Forum
Subject: Handles and pointers - basically interchangeable?


I keep stubbing my toe on the MemHandle vs. MemPtr issue, and I can't seem
to find any documentation that really does a good job of explaining how they
work, and work together. (If anyone knows of some good reading on the
subject, I'd love to know about it.)

My specific question has to do with the data that a gadget can store. I know
it stores a pointer to something (anything), but in the function
FrmSetGadgetData, can the argument that represents the pointer to the data
be a *handle* to the data instead of a pointer?

I know a handle is a moveable chunk of memory and a pointer is a nonmoveable
chunk. I know that to read or write to a chunk, you have to make it
nonmoveable (either by declaring it as a pointer right off the bat, or by
declaring it as a handle, then locking the handle, which returns a pointer -
right?). But can you use a handle instead of a pointer as an argument to
some functions? Like FrmSetGadgetData, in particular?

Finally, how important is it to use handles instead of pointers in the first
place? When my app is running, why does the OS need to be moving memory
around anyway? Or is it that idea that, while my app is running, if it's
possible to start another app, THAT's when the OS might want to move the
memory? I mean, if I use pointers instead of handles for the gadgets on a
form, but they're around only as long as the form itself is around, is this
a big deal?

Thanks so much for any input - this has caused me more grief than all other
issues combined...

Brian

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