Thanks!
--
Tim Astle
Schettino, John <[EMAIL PROTECTED]> wrote in message
news:8563@palm-dev-forum...
>
> This is what I use (which works for me)
>
> Use MemMove() when copying out of the packed buffer, to avoid memory
> alignment issues:
>
> instead of
> unpackedStruct->aBool = (Boolean *)(*c);
>
> use
> MemMove(&unpackedStruct->aBool, c, sizeof(unpackedStruct->aBool);
>
> where
> unpackedStruct is a pointer to your unpacked record struct
> c is a pointer to the packed record memory block
>
>
> So for example, I have these pack/unpack functions:
> // some example struct
> typedef struct {
> Boolean theBool;
> Char theString;
> } dbRec;
>
> // pack a record into a preallocated database record
> SavePackedRec(dbRec *rec, VoidPtr databaseMemory) {
> DmWrite(databaseMemory, 0, &rec->theBool, sizeof(rec->theBool));
> DmWrite(databaseMemory, sizeof(rec->theBool), &rec->theString,
> StrLen(rec->theString)+1);
> }
>
> // allocate local storage and unpack record
> // don't forget to free returned value when you're done with it!
> dbRec *UnpackRecord(VoidPtr databaseMemory) {
> // compute size of unpacked record
> UInt recSize = sizeof(newRec->theBool);
> recSize += StrLen(databaseMemory+recSize) + 1;
>
> dbRec *newRec = MemPtrNew(recSize);
> MemMove(&newRec->theBool, databaseMemory, sizeof(newRec->theBool));
> databaseMemory += sizeof(newRec->theBool);
> StrCopy(&newRec->theString, databaseMemory);
> return newRec;
> }
>
>
> -- John Schettino,
> Palm OS Programming for dummies: http://schettino.tripod.com
>
> -----Original Message-----
> From: Tim Astle [mailto:[EMAIL PROTECTED]]
> Sent: Monday, April 17, 2000 11:08 AM
> To: Palm Developer Forum
> Subject: Re: Weird.....
>
>
> My array was the last entry in the struct. It turns out that a Byte /
> Boolean that I added to the first of the struct caused some problems with
my
> double types.
>
> I believe I need to find out the correct procedure to pack a Byte type int
o
> a structure.
>
> --
>
> Tim Astle
>
>
>
>
> Luca <[EMAIL PROTECTED]> wrote in message news:8556@palm-dev-forum...
> >
> > When you're packing data such that your packed record contains an array
of
> > length 1 and you plan on writing beyond its limits, make sure the array
is
> > at the last entry in the struct. If not, you'll end up writing over
part
> of
> > your array since all the data is continuous and space was only reserved
> for
> > the first entry of the array!
> >
> >
> >
> >
> >
>
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
> please see http://www.palm.com/devzone/mailinglists.html
>
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palm.com/devzone/mailinglists.html