Belongs to : Keyword


The Packed keyword tells Delphi to minimise the storage taken up by the defined object.
Normally, complex data types, such as records have their elements aligned to 2, 4 or 8 byte boundaries, as appropriate to the data type. For example, a Word field would be aligned to a 4 byte boundary.
Records are also padded to ensure that they end on a 4 byte boundary.
These alignments ensure optimal access performance.
The Packed overrides this, compressing the data into the smallest storage, albeit with consequential reduced access performance.

Examples of unpacked alignments :

Word = 2 bytes
LongWord = 4 bytes
Single = 4 bytes
Double = 8 bytes

Example code