我有很多常量数组,它们的元素数量不相同。
为了存储这些数组,我声明了一个足够大的数组类型来存储(或引用?)最大的这些数组的每个元素:
type
TElements = array [1 .. 1024] of Single;
每个这些TElements数组都与另一个TElements数组逻辑相关联,而且这个数组确实有相同数量的元素。
因此,为了配对这些大小相等的数组,我声明了一种记录类型,如下所示:
type
TPair = record
n : Integer; // number of elements in both TElements arrays
x : ^TElements;
y : ^TElements;
end;
我接下来定义常量TPair记录,其中包含常量TElements数组对:
const
ElementsA1 : array [1 .. 3] of Single = (0.0, 1.0, 2.0);
ElementsA2 : array [1 .. 3] of Single = (0.0, 10.0, 100.0);
ElementsA : TPair =
(
n : 3;
x : @ElementsA1;
y : @ElementsA2;
);
ElementsB1 : array [1 .. 4] of Single = (0.0, 1.0, 2.0, 3.0);
ElementsB2 : array [1 .. 4] of Single = (0.0, 10.0, 100.0, 1000.0);
ElementsB : TPair =
(
n : 4;
x : @ElementsB1;
y : @ElementsB2;
);
这似乎是引用数组数据的一种低效方式(也许不是,我不知道)。
我想要维护一个单一的常量数据类型(一个“对”数据类型),其中包含两个常量数组。
在每个“对”中,“对”中的两个数组都保证具有相同数量的元素。
然而,并不能保证一个“对”中的数组元素数量等于任何其他“对”中的数组元素数量。
是否有一种方法声明一个常量“对”数据类型,以便所包含的数组大小由常量数组定义决定?
理想情况下,我想摆脱TElements类型和笨拙的指针。如果它能编译,那么像这样就很酷了:
type
TPair = record
x : array of Single;
y : array of Single;
end;
const
ElementsA : TPair =
(
x : (0.0, 1.0, 2.0);
y : (0.0, 10.0, 100.0);
);
ElementsB : TPair =
(
x : (0.0, 1.0, 2.0, 3.0);
y : (0.0, 10.0, 100.0, 1000.0);
);
但我猜想由于这些数组是被声明为动态数组,所以它不会在运行前分配内存?
ElementsA: array of array of Single = [[0.0,1.0,2.0],[0.0,10.0,100.0]];
- LU RD