A amli Unregistered / Unconfirmed GUEST, unregistred user! 2004-02-24 #2 variant變量是由Delphi管理的 SizeOf(variant)=16 但variant數据大小就由VarType(variant)定了.
L lich Unregistered / Unconfirmed GUEST, unregistred user! 2004-02-24 #3 16 byte 但是根据不同的数据类型它还占用额外的内存 Variant 实际上就是 TVarData Delphi中定义如下: TVarData = packed record VType: TVarType; case Integer of 0: (Reserved1: Word; case Integer of 0: (Reserved2, Reserved3: Word; case Integer of varSmallInt: (VSmallInt: SmallInt); varInteger: (VInteger: Integer); varSingle: (VSingle: Single); varDouble: (VDouble: Double); varCurrency: (VCurrency: Currency); varDate: (VDate: TDateTime); varOleStr: (VOleStr: PWideChar); varDispatch: (VDispatch: Pointer); varError: (VError: LongWord); varBoolean: (VBoolean: WordBool); varUnknown: (VUnknown: Pointer); varShortInt: (VShortInt: ShortInt); varByte: (VByte: Byte); varWord: (VWord: Word); varLongWord: (VLongWord: LongWord); varInt64: (VInt64: Int64); varString: (VString: Pointer); varAny: (VAny: Pointer); varArray: (VArray: PVarArray); varByRef: (VPointer: Pointer); ); 1: (VLongs: array[0..2] of LongInt); ); 2: (VWords: array [0..6] of Word); 3: (VBytes: array [0..13] of Byte); end;
16 byte 但是根据不同的数据类型它还占用额外的内存 Variant 实际上就是 TVarData Delphi中定义如下: TVarData = packed record VType: TVarType; case Integer of 0: (Reserved1: Word; case Integer of 0: (Reserved2, Reserved3: Word; case Integer of varSmallInt: (VSmallInt: SmallInt); varInteger: (VInteger: Integer); varSingle: (VSingle: Single); varDouble: (VDouble: Double); varCurrency: (VCurrency: Currency); varDate: (VDate: TDateTime); varOleStr: (VOleStr: PWideChar); varDispatch: (VDispatch: Pointer); varError: (VError: LongWord); varBoolean: (VBoolean: WordBool); varUnknown: (VUnknown: Pointer); varShortInt: (VShortInt: ShortInt); varByte: (VByte: Byte); varWord: (VWord: Word); varLongWord: (VLongWord: LongWord); varInt64: (VInt64: Int64); varString: (VString: Pointer); varAny: (VAny: Pointer); varArray: (VArray: PVarArray); varByRef: (VPointer: Pointer); ); 1: (VLongs: array[0..2] of LongInt); ); 2: (VWords: array [0..6] of Word); 3: (VBytes: array [0..13] of Byte); end;
要 要离 Unregistered / Unconfirmed GUEST, unregistred user! 2004-02-24 #4 我定义的是一个比较复杂的变体,有很多数据,实际内存挺大的,但不知具体大小是多少,有办法求出吗,最好是有函数
L lich Unregistered / Unconfirmed GUEST, unregistred user! 2004-02-24 #5 自己可以写一个函数,根据实际的数据类型来计算所占空间的大小 可以用递归方式实现 因为一个Variant数据,可能是字符串,可能是一个数组, 也可能是一个Variant数组
C calman Unregistered / Unconfirmed GUEST, unregistred user! 2004-03-13 #9 不是有一个内存对齐的指示字吗,如果你有一个Integer和一个Char的字段的结构,这个结构的大小是8而不是5,因为编译器为了方便存取,将小于Integer的Char也作为4个字节处理。
C calman Unregistered / Unconfirmed GUEST, unregistred user! 2004-03-13 #10 或者通过Ctrl+Alt+Del来,首先不用这个结构看看用了多少物理内存,再看看用了这个结构又用了多少物理内存,哈~