On 2007-02-20, Stephen <stephen@[EMAIL PROTECTED]
> wrote:
> I don't quite understand the difference between FreePascal's
> $PackRecords directive values.
>
> The do***entation says the values can be 1, 2, 4, 16, and C. I
> understand the default is to align on 2 byte boundaries, and that 1
> is the same as a 'packed' record, but how do I know exactly when to
> choose 2, 4, 16, etc.? Are there performance gains if I use a higher
> alignment value? Is a value of 2 OK to use all the time, regardless
> of the size of the members of the record?
As far as I got it from a recent discussion with FPC devels:
- packrecords <x> means that a field of size <x> is aligned on a <x> byte
boundery.
- A field with a larger size than <x> is also aligned on <x>
- composed fields (e.g. record in record) are aligned on the alignment of
the record. So a record that has <y> as largest field size is also aligned
as if it were a field of size <y>, even though the record can be bigger.
- packrecords C says to take the default of C. I believe it
nowadays also can be 8.
- in 2.1.1+ there is a new directive {$codealign minrecord=x} this forces
to align to minimally <x> bytes. (so also smaller entities
are aligned to this)
Afaik the performance increasements on modern x86 processors are negiable,
because the small speedups are offset by the average datastructure getting
slightly larger (and slower copied/passed by value etc).
So unless you have some specific reason (like some forms of MMX and SSE)
have to be compatible with a layout on disk or are an compiler and
assembler
expert that wants to get the most extreme performance, you can safely
ignore
it for x86.
It is a good custom to write packed records to disk exclusively, because
nearly any compiler can define something similar to a packed record.


|