Hoi
Ik loop tegen iets raars aan wat ik niet kan verklaren.
Als je naar onderstaande code kijkt en het aantal bytes op gaat tellen zie je dat er een verschil is tussen records afzonderlijk en het record waar alles in zit.
No big deal over de size maar ben benieuwd waar het verschil in bytes vandaan komt.
Wat zie ik hier over het hoofd?
Alvast bedankt,
Herby
PHP Code:
Size of rec1 is 5 bytes
Size of rec2 is 4 bytes
Size of rec3 is 32 bytes
Size of rec4 is 4 bytes
= 45 bytes
Size of rec is 48 bytes
Code:program recordtest; {$APPTYPE CONSOLE} {$R *.res} uses WinAPI.Windows, System.SysUtils; type TRec1 = record s : string[4]; // 5 bytes = 1 byte Nr of characters + 4 bytes end; TRec2 = record i : integer; // 4 bytes end; TRec3 = record arr : array [0..31] of byte; // 32 bytes end; TRec4 = record dw : DWORD; // 4 bytes end; TRec = record s : string[4]; // 5 bytes = 1 byte Nr of characters + 4 bytes i : integer; // 4 bytes arr : array [0..31] of byte; // 32 bytes dw : DWORD; // 4 bytes end; // 45 bytes ==> SizeOf(Rec) = 48 ??? var rec : TRec; rec1 : TRec1; rec2 : TRec2; rec3 : TRec3; rec4 : TRec4; begin WriteLn (Format('Size of rec1 is %d bytes',[SizeOf(rec1)])); WriteLn (Format('Size of rec2 is %d bytes',[SizeOf(rec2)])); WriteLn (Format('Size of rec3 is %d bytes',[SizeOf(rec3)])); WriteLn (Format('Size of rec4 is %d bytes',[SizeOf(rec4)])); WriteLn; WriteLn (Format('Size of rec is %d bytes',[SizeOf(rec)])); readln; end.
Bookmarks