| United States-English |
|
|
|
![]() |
HP Pascal/HP-UX Programmer's Guide > Chapter 5 Allocation and Alignment Records |
|
A record allocation is the sum of the allocations of the fields in the fixed part and (if the record has them) the allocations of the tag field and the largest field in the variant part, plus trailing bits. Field allocation depends on field type and whether the record is unpacked, packed, or crunched. The same factors determine field alignment. See the tables indicated below: Table 5-4 Array Documentation Map
The HP Pascal packing algorithm uses these two rules to align a record:
Example
A record of the type Rec is 8-byte-aligned because its most restricted field, l, must be 8-byte-aligned. The variant part of a record of type Rec is 4-byte-aligned, because the most restricted first field of the two variants, i, must be 4-byte-aligned. A variable of type Rec is allocated 16 bytes. The TRUE and FALSE variants are aligned like this: Sometimes you can reduce the space that a record takes by declaring its fields in different order. Example
The only difference between the variables upr1 and upr2 is the order of their fields. The variable upr1 takes six bytes: Because pf must be 2-byte-aligned, it cannot start in the second byte. The extra byte after cf is allocated because the most restricted element, pf, is 2-byte-aligned. The variable upr2 takes four bytes: Sometimes you cannot reduce the space that a record takes by declaring its fields in different order. Example
The only difference between the variables pr1 and pr2 is the order of their fields. The variable pr1 takes four bytes: The variable pr2 also takes four bytes: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||