There is a dynamic array consisting of records:
type ListType = (I,R,S,C,B); ElementRecord = record case TypeList: ListType of I: (IntField:integer); R: (RealField:real); S: (StrField:shortstring); C: (CharField:char); B: (BoolField:boolean); end; ExtArr = Array of ElementRecord; var RecList: ExtArr;
Then we perform such actions with it (the array itself is inside the class and the methods work with it, here I show only the result of their work in order to avoid unnecessary code):
SetLength(RecList, 1); RecList[0].TypeList := C; RecList[0].CharField := 'A'; Writeln(Sizeof(ExtArr), ' ', Sizeof(RecList), ' ', Sizeof(RecList[0])); SetLength(RecList, 2); RecList[1].TypeList := S; RecList[1].StrField := 'test'; Writeln(Sizeof(ExtArr), ' ', Sizeof(RecList), ' ', Sizeof(RecList[1]));
Console output:
4 4 264
4 4 264
That is, the size of the type is 4 bytes, the size of the array is also 4, and the size of the record - the element of the array is 264 bytes. And all this does not depend on the contents of the array elements and their number. The size of what, after all, shows the function sizeof
and how to use it correctly?
ElementRecord
is determined by the longest member of the union - theshortstring
, which can contain 255 characters plus some service bytes. - IgorSizeOf(ListType) = 1
), does not seem to be involved. Immediately after it (without alignment) there is a byte of the length of the string and the string itself. Total 257 bytes + alignment 8 bytes = 264. It turns out that the "extra" bytes are already after the line. If you putListType = Word
, then the string will start with 2 bytes (I look at the memory dump). Of course, this will not affect the overall size. - kami