Another aspect of packing is saving strings in variable-length fields and
not fixed-length. In other words, you may have a structure that defines an
element in your programs as follows:
struct MyData
{
int field1;
int field2;
char field3[32];
char field4[256];
};
For convenience and quick access, you have fixed-length fields for the
strings. This way, the compiler knows right where the strings are and can
get to them easily. However, it's unlikely that the strings fill up the
entire array allocated for them, and it would be wasteful to write the
struct to a database as-is; you'd end up writing a lot of unused space to
the database.
Therefore, some applications have Pack and Unpack routines that removes the
unused space when storing to a database, and "adding" it back when reading
from a database.
There are great examples of this in the Rhodes/McKeehan Palm Programming
book (for example, see the PackCustomer and UnpackCustomer routines at
<http://www.palm.com/devzone/docs/pptdg/ch06.htm#P615_35697>)
-- Keith
"Michael S. Davis" <[EMAIL PROTECTED]> on 05/18/99 02:11:59 PM
Please respond to [EMAIL PROTECTED]
Sent by: "Michael S. Davis" <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
cc: (Keith Rollin/HQ/3Com)
Subject: Pack/Unpack Description
Can someone summarize the purpose, benefits, and specs. of
a Pack/Unpack routine.
I have looked at the AddressBook example and it seems to
basically be a way to store a set of flags at the beginning
of a record that indicates which fields have been stored in
the record. Therefore one does not have to save unnecessary
field data.
So, if one wants to save the 1st, 5th and 10th fields, by
setting the 1st, 5th and 10th flag, allows one to programatically
know what was saved and where it should be retrieved to. How's that
for one long sentance:-)?
Is there more to Pack/Unpack than this?
----------------------------------------------------
Shoot-to-Win
Protect the 2nd Amendment
----------------------------------------------------