在宣布分配数组Fortran 90的差异 [英] Fortran 90 Differences in declaring allocatable array

查看:161
本文介绍了在宣布分配数组Fortran 90的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

integer, intent(in) :: n
integer, dimension(:), allocatable :: a
allocate(a(n))

integer, intent(in) :: n
integer, dimension(n) :: a

在这情况下,我们会使用第一个版本?
也许我误解分配数组,是第二个版本,甚至可分配数组?

In which situation would we use the first version? Perhaps I misunderstood allocatable array, is the second version even an allocatable array?

推荐答案

第二种情况确实不具有 A 分配的。然而,这是,一个的自动的对象。

The second case indeed doesn't have a allocatable. It is, however, an automatic object.

忽略在执行层面的内存使用的实际差异,有一个很大的区别。是的,每个 A 是(假设东西的问题没有明确规定)的局部变量是,在分配及的自动创建,大小 n个,但在第一种情况下它是可分配的。它可以被解除分配,重新分配(可能为不同的尺寸),并再次释放。等等。

Ignoring the practical differences in memory use at the implementation level, there is a big difference. Yes, each a is (assuming things not explicitly stated in the question) a local variable which is, after the allocate and the automatic creation, of size n, but in the first case it is allocatable. It can be deallocated, reallocated (perhaps to a different size), and deallocated again. And so on.

自动对象(第二种情况)不能。

The automatic object (second case) cannot be.

这篇关于在宣布分配数组Fortran 90的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆