Fortran 90 allows arrays to be created on-the-fly; these are known as deferred-shape arrays and use dynamic heap storage (this means memory can be grabbed, used and then put back at any point in the program). This facility allows the creation of ``temporary'' arrays which can be created used and discarded at will.
Deferred-shape arrays are:
INTEGER, DIMENSION(:), ALLOCATABLE :: ages REAL, DIMENSION(:,:), ALLOCATABLE :: speed
ALLOCATE(ages(1:10), STAT=ierr) IF (ierr .NE. 0) THEN PRINT*, "ages: Allocation request denied" END IF ALLOCATE(speed(-lwb:upb,-50:0),STAT=ierr) IF (ierr .NE. 0) THEN PRINT*, "speed: Allocation request denied" END IF
In the ALLOCATE statement we could specify a list of objects to create but in general one should only specify one array statement; if there is more than one object and the allocation fails it is not immediately possible to tell which allocation was responsible. The optional STAT= field reports on the success of the storage request, if it is supplied then the keyword must be used to distinguish it from an array that needs allocating. If the result, (ierr,) is zero the request was successful otherwise it failed. This specifier should be used as a matter of course.
There is a certain overhead in managing dynamic or ALLOCATABLE arrays -- explicit-shape arrays are cheaper and should be used if the size is known and the arrays are persistent (are used for most of the life of the program). The dynamic or heap storage is also used with pointers and obviously only has a finite size -- there may be a time when this storage runs out. If this happens there may be an option of the compiler to specify / increase the size of heap storage.
Return to corresponding overview page