China Blue Veins
4/14/2011 1:37:00 AM
In article <4cfd6690-b0a0-4ecc-ac59-fc56863d67b9@d12g2000vbz.googlegroups.com>,
Der Engel <engelster@gmail.com> wrote:
> Hi,
>
> Why does the following code returns 28 in a i386 machine and 32 in a
> amd64 machine? I guess this is more of a implementation/machine
> question.
>
>
> #include <stdio.h>
>
> struct flex
> {
> int count;
> double average;
> double scores[2];
> };
>
> int main(void)
> {
> printf("%zd\n", sizeof (struct flex));
> return 0;
> }
You can check sizeof(int) and sizeof(double).
sizeof(double) is likely to be 8, and size(int) is likely to be 4 or 8. If 4,
the minimum size is 4+8+2*8 = 28; if 8, 8+8+2*8 = 32. Also there may be
alignment issue where it's possible amd64 sizeof(int)=4 but it wants fields (or
at least double fields) on an 8 byte boundary, so it inserts 4 extra bytes of
padding to align the fields.
Unless you have a real need to worry about it, don't. Allocation size is usually
irrelevant with virtual memory.
--
Damn the living - It's a lovely life. I'm whoever you want me to be.
Silver silverware - Where is the love? At least I can stay in character.
Oval swimming pool - Where is the love? Annoying Usenet one post at a time.
Damn the living - It's a lovely life. I am in the Nile.