更新时间:2022-06-08 00:08:13
TBytes
和 TIdBytes
都实现为动态数组,只是声明方式不同.政治上正确"的解决方案是复制字节.但这会浪费大型阵列的内存.一个简单的解决方案是使用类型转换,以便您可以利用数组的内部引用计数,例如:
TBytes
and TIdBytes
are both implemented as dynamic arrays, they are simply declared differently. The "politically correct" solution is to make a copy of the bytes. But that can waste memory for large arrays. A simpler solution is to use a typecast so you can utilize the array's internal reference count, eg:
type
PIdBytes = ^TIdBytes;
var
B1: TBytes;
B2: TIdBytes;
begin
B1 := ...;
B2 := PIdBytes(@B1)^;
end;
或者简单地:
var
B1: TBytes;
B2: TIdBytes;
begin
B1 := ...;
B2 := TIdBytes(B1);
end;