Tôi hiểu rằng thuộc tính align
có hình thức sử dụng few different.Lẫn lộn về thuộc tính 'căn chỉnh'
Trong nỗ lực đầu tiên của tôi, tôi đã sử dụng nó như sau:
align(1)
private struct TGAHeader
{
ubyte idLenght;
ubyte hasColormap;
ubyte imageType;
ushort cmFirstEntry;
ushort cmLength;
ubyte cmSize;
ushort xOrigin;
ushort yOrigin;
ushort width;
ushort height;
ubyte pixelDepth;
ubyte imageDescriptor;
}
// TGAHeader.sizeof == 20
nào dẫn đến việc struct được đệm bằng 2 byte thêm không mong muốn.
Sau khi thay đổi nó để:
private struct TGAHeader
{
align(1):
ubyte idLenght;
ubyte hasColormap;
ubyte imageType;
ushort cmFirstEntry;
ushort cmLength;
ubyte cmSize;
ushort xOrigin;
ushort yOrigin;
ushort width;
ushort height;
ubyte pixelDepth;
ubyte imageDescriptor;
}
// TGAHeader.sizeof == 18
tôi đã dự kiến 18 byte cho kích thước tiêu đề. Vì vậy, nghi ngờ của tôi là: Việc sử dụng thực tế của hình thức đầu tiên của thuộc tính align
là gì nếu nó dường như không căn chỉnh dữ liệu như mong đợi?