RISC Machine Data Structure Word Alignment Problems?

weaver at weitek.WEITEK.COM weaver at weitek.WEITEK.COM
Wed Jan 24 04:21:18 AEST 1990


In article <51245 at bbn.COM> slackey at BBN.COM (Stan Lackey) writes:
>Just a quick summary of the last time we went around on this issue:
>
>There are a number of interesting applications that build many
>instances of small data structures, each containing varied data types.
>It was said that logic simulators do this.  In a machine that forces
>you to always have data aligned, this can result in lots of wasted
>memory.  Not because the programmer is stupid, but because of the
>nature of the application.
>

I want to point out here that this data alignment problem can be 
mostly worked around for application programs. 

On a machine with "natural" alignment, a structure (record, common) 
made of primitive data items (integers, pointers, floats, etc.) 
needs no padding if the elements are ordered such that smaller items 
always follow larger items. The size ordering of primitive data
items is machine dependant, but similar from one machine to the next. 
If the entire record is not a multiple of the largest required alignment,
then some space may be lost between structures, or in nested 
structures. This cannot be handled so easily.

In summary, if you are writing an application from scratch, you
can minimize this effect in an almost (but not quite!) machine
independant way. So for new programs, I think natural alignment
is a good time/speed tradeoff. I also think that supporting 
unaligned data by both traps and special in-line code is a good
idea, since so many programs have long histories. 


Michael.



More information about the Comp.lang.c mailing list