1

我是 Fortran 新手。我面临指针数组的问题。我正在用 Fortran90 编写代码。由于数据量大,我必须使用指针数组。伪代码是这样的

type  ::a
   integer   ::Id
   real       ::Coords(3)
end type a
type ::b
    type(a),pointer   ::Member 
end type b
type(b),allocatable   ::data(:)
integer               ::i
!allocation and assigning
allocate(data(n))
do i=1,n
    allocate(d(i)%member)
    d(i)%member%Id = i
    d(i)%member%Coordinates(:) = i*2.0
end do

!Some stuff using data

!De allocation
do i=1,n
    deallocate(d(i)%member)
end do
deallocate(data)

我观察到以这种方式释放指针数组非常慢。在处理数百万个数据集时,需要花费大量时间。如果我不这样做,内存就不会被释放。我想通过分配新的大小(伪代码中的新 n 值)来重用数据而不退出程序。所以我不能在不释放数组的情况下逃跑,否则将没有足够的内存来做接下来的事情。

任何人都可以建议我是否可以通过其他方式在 Fortran 中释放指针数组?或者我可以在我的 Fortran 程序中处理大型数据集吗?

谢谢

4

0 回答 0