2010-11-26 59 views
2

我想在Ada中动态分配一个大数组(以及数组的数组)。 举例来说,我能够动态分配一个对象,像这样:动态数组在Ada中的记录分配

type Object; 
type ObjPtr is access Object; 
OP : ObjPtr; 
-- sometime later 
OP := new Object; 
OP.Index := I;--OP.Ptr.all; 
Free(OP); 

我试图仿效这一基准代码:

Object **objList = new Object*[500000]; 
int32_t *iList = new int32_t[500000]; 
for (int32_t i = 0; i < 500000; ++i) 
{ 
    objList[i] = new Object; 
    iList[i] = Object::getIndex(objList[i]); 
    delete objList[i]; 
} 
delete[] iList; 
delete[] objList; 

可悲的是,我不能,甚至做一些事情这样的C++相当于:

Object *objList = new Object*[500000]; 

我想出了这么多,到目前为止:

type objs is array (Positive range <>) of Object; 
type objList is access objs; 

但我很可能离开。

+0

数组的数组在哪里? – Schedler 2010-11-26 11:12:15

回答

1

在阿达你的C++代码将大致转化为以下几点:如果你想使用调度业务与你的对象(即Object被定义为标签类型

Alloc_Count : constant := 500_000; 
type ObjPtr is access Object; 
type ObjArray is array (1 .. Alloc_Count) of ObjPtr; 
OA : ObjArray; 
begin 
    for I in OA'Range loop 
    OA(I) := new Object; 
    -- ... do the other things 
end loop; 

,用Object'class代替ObjectObjPtr声明中。