At 2:15 PM -0700 5/4/99, Jason Dawes wrote:
>This problem is endemic to the whole "event-driven" world, and it stems
>from the interface not being owned by your application. In the Palm
>paradigm, an application is basically just a glorified collection of
>scripts, and the only thing holding it together is global memory.
Yes, exactly.
But that's not necessarily bad.
How many forms do you have open at once? Hopefully the number is two or
less -- a application form and maybe a temporary dialog.
So go ahead and use a couple of global pointers -- 8 bytes out of your
global space isn't so bad. Allocate a chunk (MemPtrNew) when the form
opens, delete it when the form closes. Null out the global pointer to
indicate the data is gone.
True, it's not quite as elegant as having the form keep track of user data
for you. It's certainly not object oriented.
On the other hand, the object oriented approach would mean 4 bytes extra
for every object that allows userData. (Forms, windows, lists, controls,
etc.) Add that all up, and it can be significant space. ...and most apps
probably won't use most of those pointers.
In conclusion--a global isn't really any worse: it's 4 bytes of dynamic
heap gone either way. And in many ways it's better: there are only as many
as necessary, they're much faster to access, and the OS doesn't get
involved.
KISS?
--Bob