The reserved word
packed tells the compiler to use as little memory as possible for a particular complex data type.
packed, the compiler may insert extra unused bytes between members in order to align the data on full word boundaries for faster access by the CPU.
1 program packedDemo(input, output, stderr); 2 3 type 4 signedQword = record 5 value: qword; 6 signum: -1..1; 7 end; 8 9 signedQwordPacked = packed record 10 value: qword; 11 signum: -1..1; 12 end; 13 14 begin 15 writeLn(' signedQword: ', sizeOf(signedQword), 'B'); 16 writeLn('signedQwordPacked: ', sizeOf(signedQwordPacked), 'B'); 17 end.
packed sacrifices some speed while reducing the memory used.
Smart ordering of record elements can mitigate the issue.
In the example above
signedQword as well
signum located at an offset of
That is OK.
If for any reason
signum were listed in reverse order,
signum would appear in both versions at an offset of
0, but in the
value has an offset of
This might cause a potentially slower access to the