[LCP]Data alignment

David Spencer David.W.Spencer at oracle.com
Wed Jan 9 21:03:42 UTC 2002


It depends on the processor.  On, for instance, the 68000, attempting to
read more than one byte at an odd address generates a processor
exception.  In later versions, such as the 68020, the exception is
removed and the processor does two 16 bit reads and some shuffling to
get the bytes in the right order.  On something like the 6502 or the
Z80, it makes no difference and any values can be read from any
address.  32 and 64 bit processors probably do similar things to the
68020 when reading 32/64 bit values at non-4/8-word boundaries; I
wouldn't have thought modern processors would throw an exception  for
such a trivial reason.

Therefore alignment and packing depend on the application.  Whatever the
arrangement, if performance is satisfactory then nothing needs
changing.  If data misalignment is demonstrated to be the cause of a
performance slowdown, then it should be aligned.


Priya wrote:
> 
> This is more of a conceptual question.
> We know that multibyte data must be aligned on a
> natural boundary.That is four byte dta on a four byte
> boundary and two byte data on two byte boundary and so
> forth.But what is the reason behind this.CAn anyone
> please explain.What will be the problem if the data is
> not aligned???
-- 
David Spencer
www.curlypi.com



More information about the linuxCprogramming mailing list