At 4:14 PM -0800 3/22/1999, Michael S. Davis wrote:
>Now I'm confused again. I thought this was supposed to get easier:-)
Sorry to add to the confusion. Let's see if this'll help...
>I use a structure:
>
>typedef struct {
>string string1[20];
>double elem1;
>double elem2;
>string string2[8];
>} RecordStruct;
>
>RecordStruct rec;
>
>Then I use a DmWrite(RecPointer, 0, &rec, sizeof(rec));
>to write data to DB.
>
>And I use MemMove(&rec, RecPointer, sizeof(rec));
>to fill the structure.
>
>Do I have to do anything to take into consideration
>the possiblity of elem1 and elem2 falling on the wrong
>boundaries, since I am using MemMove and DmWrite. Or, is
>that handled automatically by DmWrite and MemMove.
Actually, the compiler will add padding to your struct. In your case, your strings
have even size, so it doesn't need to do anything. If you declared char string1[21],
the compiler would add a dummy field just after it to make the elem1 double land at an
even offset within the struct. If you had such an odd-size string, you could avoid
this padding by using DmWrite and MemMove on individual fields, but this would be much
slower than your current approach.
Your situation doesn't present a problem. All the fields in your record are even size,
so no padding is required.
>Related question. The sizeof(rec) produces a value. Is
>that the same size as the data in the DB? It seems to be but
>my string arrays are even in size and maybe that is a
>coincidence.
The sizeof "function" includes any padding that the compiler adds. If you use DmWrite
and MemMove on the entire record, then your record will also have padding, so the two
should be the same size. Of course, it's up to you to actually create your records
with the proper size.
Hope this helps.
-
Danny Epstein * mailto:[EMAIL PROTECTED]
Applied Thought Corporation * http://www.appliedthought.com
Flytrap for PalmOS * http://www.appliedthought.com/flytrap