範例
type // Declare an unpacked record TDefaultRecord = Record name1 : string[4]; floater : single; name2 : char; int : Integer; end; // Declare a packed record TPackedRecord = packed Record name1 : string[4]; floater : single; name2 : char; int : Integer; end; var defaultRec : TDefaultRecord; packedRec : TPackedRecord; begin ShowMessage('Default record size = '+IntToStr(SizeOf(defaultRec))); ShowMessage('Packed record size = '+IntToStr(SizeOf(packedRec))); end;
結果
Default record size = 20
Packed record size = 14
P.S. I didn't compile this code, I don't know why the size is 20 and 14. But the concept is reasonable.
沒有留言:
張貼留言