Search code examples
modulefortranfortran90fortran-common-block

Is there a difference memory-wise between using Common Blocks and Modules in Fortran 90


I am recently learning Fortran without any guidance, and experimenting with different versions. I have found from this site:

Is a MODULE better than a COMMON block?

Almost always yes. The only reasons to use COMMON blocks are if you expect to use your program on a computer with only a FORTRAN 77 compiler (they still exist), or if it is very important that you control the order in which your data is stored in memory.

Well, using modules is surely syntactically sweeter than using common blocks. But what are the differences in terms memory usage and allocation in both cases? Also does it make a difference in terms performance and access speed? Does that question make sense?


Solution

  • M.S.B. has it in his answer, but does not stress it enough in my opinion. The variables in COMMON blocks are laid out in memory exactly in the order in the definition of the block. From this the restriction, that no dynamic memory objects (allocatable, pointer) can be in a COMMON block, immediately follows.

    The "sequence association" means you can count on the placement of the variables in such a way that you can, e.g., use two following arrays as a large one.

    COMMON blocks have probably no place in modern code, although they are not declared obsolete.

    When it comes to speed, if the variable is the same, there shouldn't be any difference in accessing it, whether it is in a module or in a COMMON block.