Shailesh: As used by the built-in apps, Joe's answer is not quite correct.
When "unpacking", the built-in applications do not actually copy or move any data. Instead they lock the record containing the "packed" data, and fill in pointers to it in the "unpacked" structure. These pointers can then be given directly to field gui elements which will move the remainder of the record around when the user edits (lengthening or shortening) one of the fields. Of course doing this invalidates the other pointers, so the built-in apps carefully use SaveData callbacks to keep things straight. When "packing", the pointers can be pointing to anywhere -- within a (locked) record, to the heap, to the stack, etc. The "packing" routines assemble a "packed" record by determining the packed size, allocating a new handle, and moving the data from the areas pointed to by the "unpacked" record to the new record under construction. This all is a very flexible approach that minimizes the amount of long-term storage used (in the database). It can, however, be quite unintuitive to someone just reading the example code! -bob mckenzie, palmsource pdx -----Original Message----- From: Joe [mailto:[EMAIL PROTECTED]] Sent: Monday, March 04, 2002 11:52 AM To: Palm Developer Forum Subject: Re: Pack/Unpack (was: palm-dev-forum digest: February 24, 2002) --- shailesh k phalle wrote: > what is packing & unpacking of data UnPacked data: -------------- typedef struct { Char first[15]; Char last[15]; } myRecord; example: myRecord r; StrCopy(r.first, "Joe"); StrCopy(r.last, "Baloney"); the result is Joe0***********Baloney0******* (where * represents any char, 0 represents '\0') Packed data: ------------ typedef struct { Char *firstlast; } myPackedRecord; example: myPackedRecord pr; pr.firstlast = MemPtrNew(12); MemMove(pr.firstlast, "Joe", 4); MemMove(pr.firstlast+4,"Baloney", 8); the result is Joe0Baloney0 The packed data takes up less space on your handheld. But, before your program can use it, the data must be unpacked -- separated into the two strings, first and last. (Apoligies in advance if there are any typos in the above, untested, code.) __________________________________________________ Do You Yahoo!? Yahoo! Sports - sign up for Fantasy Baseball http://sports.yahoo.com -- 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/
