308
Appendix A: System Routines — Apps
TI
-
89 / TI
-
92 Plus Developer Guide
Not for Distribution
Beta Version January 26, 2001
OO_appSetPublicStorage
(continued)
typedef struct
{
USHORT flags;
char name[40];
BCD16 result;
} GLOBALS;
n
GLOBALS g;
o
.
.
.
void main(pFrame self, Event *e)
{
HANDLE h;
switch (e->command)
{
.
.
.
case CM_PACK:
/* Getting ready to garbage collect -- save global variables */
h = HeapAlloc(sizeof(GLOBALS));
p
if (h != H_NULL)
{
GLOBALS *pg = HeapDeref(h);
*pg = g;
q
OO_appSetPublicStorage(h);
r
}
else
OO_appSetPublicStorage(H_NULL);
break;
case CM_UNPACK:
/* Garbage collect is finished -- restore global variables */
h = OO_appGetPublicStorage();
s
if (h != H_NULL)
{
GLOBALS *pg = HeapDeref(h);
g = *pg;
t
HeapFree(h);
u
}
break;
n
Declare all the global variables that need to be saved in a single structure.
o
Define a struct variable to hold the global variables.
p
Allocate memory from the heap to hold the global variables.
q
Copy the global variables to the heap.
r
Save handle to global variables in public storage.
s
Recover handle to global variables from public storage.
t
Copy global variables from heap to data segment.
u
Do not forget to release heap memory.