This documentation was styled with a demo skin from the Premium Pack 4 add-on for Help & Manual. The contents of the skin are encrypted and not configurable. You can only publish HM projects with this skin. You cannot edit it or change it.
This version is copyright and may only be used for local testing purposes. It may not be distributed.
Please purchase the full version of the Premium Pack to get the configurable skins and remove this notice. The package will also include the Toolbox configuration utility for Premium Pack skins.
Element alignment
By default, the elements are tightly packed in memory, one after each other.
You can alter this behaviour by specifying alignment modifier. It can take 3 different values:
1.byte, for 1 byte alignment
2.word, for 2 byte alignment
3.dword, for 4 byte alignment
The default packing is on byte level, so you don't really need to specify it.
In case you want to pack values aligned to 4 byte steps, you might consider using DWORD modifier.
Let's have a look at this example:
TYPE RGBColor
R AS BYTE
G AS BYTE
B AS BYTE
END TYPE
By default, the size of RGBColor will be 3 bytes, as you can verify with SizeOf:
msgBox SizeOf(RGBColor)
3 elements, each 1 byte in size.
To apply 32bit alignment, use DWORD modifier:
TYPE DwordAlignedRGBColor DWORD
R AS BYTE
G AS BYTE
B AS BYTE
END TYPE
This means that R, G and B elements will still be of byte data type, however their element offset will change to 4 byte jumps.
You can verify it easily:
DIM colorNormal AS RGBColor
msgbox strFormat$("The offset of .R is {1}, .G is {2} and .B is {3}",
UDT_ElementOffset(colorNormal.r),
UDT_ElementOffset(colorNormal.g),
UDT_ElementOffset(colorNormal.b))
DIM colorAligned AS DwordAlignedRGBColor
msgbox strFormat$("The offset of .R is {1}, .G is {2} and .B is {3}",
UDT_ElementOffset(colorAligned.r),
UDT_ElementOffset(colorAligned.g),
UDT_ElementOffset(colorAligned.b))