(Sorry for the late response, but things've been
a bit crunched around here...)
I got that far, Neil ... but what I don't understand
is this: if the ptrs in the unpacked customer record
are merely pointing into the packed customer record;
how can you change the city from "Taos" to "Dallas"
in the form without tromping all over the phone #?
If there is code to move the phone # up when changing
the city, I didn't see it. Did I just miss it, or is
there some magic being performed by the OS to do this?
--
-Richard M. Hartman
[EMAIL PROTECTED]
186,000 mi./sec ... not just a good idea, it's the LAW!
> -----Original Message-----
> From: Neil Rhodes [mailto:[EMAIL PROTECTED]]
> Sent: Friday, May 28, 1999 5:15 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Pack and Unpack question
>
>
> > According to the example of UnpackCustomer shown on the book of Palm
> > Programming,
> >
> > the function prototype of UnpackCustomer is :
> > static void UnpackCustomer(Customer *customer, const PackedCustomer
> > *packedCustomer)
> >
> > However the voidPtr to the locked record is passed as the
> second parameter.
> > Even so, packedCustomer->customerID and
> packedCustomer->name is still
> > valid. Is it because of the fact that every element in a
> structure is
> > written consecutively and in the order specified in the structure
> > declaration?
> >
>
> I think what the authors intended was the following:
>
> A packed customer (in a database record) is stored as a
> 4-byte ID, followed
> by 4 null-terminated strings (name, address, city, phone).
>
> Here's the declaration
>
> typedef struct {
> SDWord customerID;
> char name[1]; // actually longer than 1
> } PackedCustomer.
>
> Here's an example of the bytes of a (small) packed customer:
> 0x00 0x00 0x00 0x52 'N' 'e' 'i' 'l' '\0' 'M' 'a' 'i' 'n'
> '\0' 'R' 'e'
> 'd' 'l' 'a' 'n' 'd' 's' '\0' '7' '9' '3' '-' '5' '9' '9' '5' '\0'
>
> Notice that the name will always start at offset 4 within the
> packed record.
>
> An unpacked customer is used in memory, to actually access the name,
> address, city, and phone.
>
> typedef struct {
> SDWord customerID;
> const char *name;
> const char *address;
> const char *city;
> const char *phone;
> } Customer;
>
> It has four character pointers which point into the
> appropriate offsets
> within the associated (locked) PackedCustomer.
>
> If the example packed customer above were at memory address
> 0x1230, then the
> Customer would be
> 0x00000052 // id
> 0x1234 // offset 4 within packed customer
> 0x1239 // offset 9 within packed customer
> 0x123e // offset 14 within packed customer
> 0x1247 // offset 23 within packed customer
>
> The authors should have made it more clear in the book, but I
> think they
> (incorrectly) assumed this was a well-known, or obvious technique.
>
>
> Neil
>
>