On Mon, 22 Mar 1999, Danny Epstein wrote:
> >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.
>
> 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.
But my questions is, If I use DmWrite and MemMove, is that padding added
automatically, with both of these functions. I assume DmWrite does but
I am not sure about MemMove which works with pointers and does not know
what kind of data is being moved.
>
> >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
>
>
----------------------------------------------------
Shoot-to-Win
Protect the 2nd Amendment
----------------------------------------------------