Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework


Type alignment masks (Win32 only)



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə252/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   248   249   250   251   252   253   254   255   ...   294
DelphiLanguageGuide

Type alignment masks (Win32 only)
Type
Alignment
Ordinal types
size of the type (1, 2, 4, or 8)
Real types
2 for Real48, 4 for Single, 8 for Double and Extended
211


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.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   248   249   250   251   252   253   254   255   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin