我开发类来表示特殊类型的矩阵:如何在Delphi中为指向数组的指针保留内存?
type
DifRecord = record
Field: String;
Number: Byte;
Value: smallint;
end;
type
TData = array of array of MainModule.DataRecord;
type
TDifference = array of DifRecord;
type
TFogelMatrix = class
private
M: Byte;
N: Byte;
Data: ^TData;
DifVector: ^TDifference;
procedure init();
public
constructor Create(Rows, Cols: Byte);
destructor Destroy;
end;
现在在构造函数中,我需要保留内存数据和DifVector类成员。如您所见,我使用指向数组的记录。所以,主要问题是,我如何正确地保留内存?我想我不能使用这样的事情:
new(Data);
原因我真的失去了主要的想法 - 预留存储空间,就像我想,在运行时。感谢您的评论。
new(DifVector);
和数据呢?它是一个矩阵,所以我需要使用2个参数?
SetLength(Data, M, N)?
– chester89 2008-11-27 22:32:54