delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/09/11:35:51

Date: Thu, 9 May 1996 19:25:13 +0400 (MSD)
From: "Alexander V. Lukyanov" <lav AT video DOT yars DOT free DOT net>
Message-Id: <199605091525.TAA16776@video.yars.free.net>
To: j DOT aldrich6 AT genie DOT com, kagel AT dg1 DOT bloomberg DOT com
Cc: djgpp AT delorie DOT com
Subject: Re: more sizeof questions

> From: kagel AT quasar DOT bloomberg DOT com
> j DOT aldrich AT genie DOT com responded on 05/08/96 3:15 UTC
> 
>    Each of your 2-byte fields gets another 2 bytes of padding on it, for
>    a total of 260.  There IS a workaround, though, in the form of the gcc
>    __attribute__ ((packed)) command.  See my last post for details.
> 
> Not quite.  Actually, each field does NOT need word-alignment.  Only objects
> whose size is >= 4 bytes (long, int, float, long long & double [did I miss
> any?]) require word (4byte) address alignment.  The member TotalMemory is not
> padded as both it and the char array Info require 2byte alignment.  The extra
> two bytes are added at the end of the structure to insure that each element of
> an array of _VGAInfoBlock's will each have their first member, VESASignature,
> aligned.

IMHO, only char is never aligned. Any field crossing 4-byte memory boundary
should be aligned at the boundary, so it can be fetched from memory at once.
If a field is larger than 4 bytes, then it should be aligned so that it
crosses not more than (size-1)/4 such boundaries.

The reasin for that is memory ability to retrieve only aligned words,
so if a word crosses 4-byte boundary processor actually need to retrieve
two words, that take more time of course.

Some processors (mostly RISC, IMHO) can't retrieve not aligned words at all.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019