Short string types 1
Array types
same as the element type of the array.
Record types
the largest alignment of the fields in the record
Set types
size of the type if 1, 2, or 4, otherwise 1
All other types
determined by the $A directive.
To ensure proper alignment of the fields in an unpacked record type, the compiler inserts an unused byte before
fields with an alignment of 2, and up to three unused bytes before fields with an alignment of 4, if required. Finally,
the compiler rounds the total size of the record upward to the byte boundary specified by the largest alignment of
any of the fields.
If two fields share a common type specification, they are packed even if the declaration does not include the packed
modifier and the record type is not declared in the
{$A-}
state. Thus, for example, given the following declaration
type
TMyRecord = record
A, B: Extended;
C: Extended;
end;
A
and
B
are packed (aligned on byte boundaries) because they share the same type specification. The compiler
pads the structure with unused bytes to ensure that
C
appears on a quadword boundary.
When a record type is declared in the
{$A-}
state, or when the declaration includes the packed modifier, the fields
of the record are not aligned, but are instead assigned consecutive offsets. The total size of such a packed record
is simply the size of all the fields. Because data alignment can change, it's a good idea to pack any record structure
that you intend to write to disk or pass in memory to another module compiled using a different version of the compiler.
Dostları ilə paylaş: