[fpc-pascal] Memory alignment with FPC

Nico Erfurth fpc at erfurth.eu
Wed Oct 10 15:04:41 CEST 2012


On 10.10.12 14:40, dhkblaszyk at zeelandnet.nl wrote:

> One more question, when using packed records, is there anything to say
> about performance? Are there some tests anywhere that show how the
> performance is impacted?

This highly depends on the architecture/processor.

Many architectures (like older ARMs) can not handle unaligned access at
all. Such an access would create an exception, which has to be handled
by the system (Linux provides the capability to emulate these faults,
but at a VERY high performance cost). Thats why fpc emits byte loads for
halfword and word loads on packed records. But for a words these will
also take about 7-15 cycles, depending in the compiler version and core
used. Newer ARM implementations can handle unaligned access, but only
under some performance penalty.

x86 can handle unaligned access, but most implementations (I think
current atoms and via nano are an exception) will suffer a rather high
performance penalty.

If you only use packed records to get your data from and to disk/network
you'll not see much of a difference, but you should avoid using a packed
record inside something which is performance sensitive.

Nico



More information about the fpc-pascal mailing list