At 1:08 PM -0400 2001/06/04, Brian Smith wrote:
>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?

Yes. As far as the OS is concerned, it's nothing more than 4 consecutive bytes in the 
gadget's internal data structure.


>Finally, how important is it to use handles instead of pointers in the first
>place?

Handles help to avoid heap fragmentation, while pointers help to enforce 
fragmentation. Which one is more appropriate depends entirely on your code's design 
and use of the dynamically allocated memory block. Generally speaking, however, you 
should use handles whenever possible, and keep them unlocked as much as possible.


>When my app is running, why does the OS need to be moving memory
>around anyway?

Because the heap is very small, fragmentation can cause dynamic memory allocations to 
fail when there is no single consecutive block of bytes large enough to satisfy the 
request. Handles avoid this situation by allowing the OS to move previously-allocated 
blocks around, thus creating a larger block of consecutively free bytes which can 
satisfy the request.

Regards,

Jim Schram
Palm Incorporated
Partner Engineering


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