如下的结构: Ttest = Record
a: LongInt; //4
b: Byte; //1
c: Boolean; //1
d: Boolean; //1
e: Boolean; //1 f: Double; //8
g: Word; //2
h: Word; //2
i: Word; //2
j: Word; //2
k: LongInt; //4
l: Double; //8
end;Sizeof(TTest) = 40;
但我用手工算来算去,都只有36, 为什么?
Word ----- 2 Byte;
Boolean ---- 1 Byte
LongInt ---- 4 Byte
Double ----- 8 Byte谢谢!
a: LongInt; //4
b: Byte; //1
c: Boolean; //1
d: Boolean; //1
e: Boolean; //1 f: Double; //8
g: Word; //2
h: Word; //2
i: Word; //2
j: Word; //2
k: LongInt; //4
l: Double; //8
end;Sizeof(TTest) = 40;
但我用手工算来算去,都只有36, 为什么?
Word ----- 2 Byte;
Boolean ---- 1 Byte
LongInt ---- 4 Byte
Double ----- 8 Byte谢谢!
SET TO 1. 就没问题。
a: LongInt; //4
b: Byte; //1
c: Boolean; //1
d: Boolean; //1
e: Boolean; //1 f: Double; //8
g: Word; //2
h: Word; //2
i: Word; //2
j: Word; //2
k: LongInt; //4
l: Double; //8
end;
a: LongInt; //4
b: Byte; //1
c: Boolean; //1
d: Boolean; //1
e: Boolean; //1 f: Double; //8
g: Word; //2
h: Word; //2
i: Word; //2
j: Word; //2
k: LongInt; //4
//-------------------〉这里有4位为空的,没有packed下面的l要求安八位地址对齐
l: Double; //8
a: LongInt; //4
b: Byte; //1
c: Boolean; //1
d: Boolean; //1
e: Boolean; //1 f: Double; //8
g: Word; //2
h: Word; //2
i: Word; //2
j: Word; //2
k: LongInt; //4
n:longint; -------------------〉插入一个四位的变量
l: Double; //8sizeof(test)=40 没有增加
还是不太明白,如果你把其中的一些变成extend(10),结果还是不对,没有找到规律,
但是用packed record的绝对没错,没有对齐的概念,是挨着存的