next up previous contents index
Next: COMMON Statement Up: Common Blocks Previous: Restrictions

Blank Common Blocks

Common blocks are sometimes also used to reduce the total amount of memory used by a program by arranging for several program units to share the same set of memory locations. This is a difficult and risky procedure which should not be attempted unless all else fails.

Most Fortran systems operate a storage allocation system which is completely static: each program unit has a separate allocation of memory for its local variables and arrays. If several procedures each need to use large arrays internally the total amount of memory occupied by the program may be rather large. If a set of procedures can be identified which are invoked in sequence, rather than one calling another, it may be feasible to reduce the total memory allocation by arranging for them to share a storage area. Each will use the same common block for their internal array space.

Named common blocks are required to have the same length in each program unit: if they are used it is necessary to work out which one needs the most storage and pad out all the others to same length. An alternative is to the use the special blank (or un-named) common block which has the useful property that it may have a different length in different program units.

In one program unit, for example, you could specify:

 
       COMMON // DUMMY(10000)

and in another

 
       COMPLEX SERIES(512,512), SLICE(512), EXPECT(1024) 
       COMMON // SERIES, SLICE, EXPECT

The blank common block has two other special properties. Firstly it cannot be initialised by a DATA statement even within a BLOCK DATA program unit (but this is not a serious limitation for a block used just for scratch storage). Secondly items within the blank common block never become undefined as a result of a procedure exit. For this reason the blank common block cannot be specified in a SAVE statement.


next up previous contents index
Next: COMMON Statement Up: Common Blocks Previous: Restrictions

Mario Storti
Wed Nov 4 19:32:56 ART 1998