Reputation: 43
I'm responsible for a number of legacy (F77) programs. On occasion one or another may fail due to attempting to exceed a fixed array size. My usual fix is to way over allocate the offending array.
Does anyone have thoughts or experience on changing these fixed arrays to dynamic and what are the ramifications to the rest of the code including subroutine calls?
I'm using a fairly new compiler on OpenVMS so I believe that there will not be compiler issues.
Upvotes: 3
Views: 1839
Reputation: 78316
Can you be a bit clearer about what you currently do and what you propose to do ? You state that you 'way over allocate' arrays, which suggests that you are already using dynamic arrays, then in the next sentence you ask about changing fixed arrays to dynamic.
Perhaps you mean that you define the arrays, at compile time, with more space than you expect to use ? That's one of the ways Fortran programmers have worked for a long time. Since Fortran 90, however, the language has supported, in a standard way, dynamic arrays, ie those whose size is established at run time. The keyword ALLOCATABLE is used to declare such arrays, and they are given space (on the heap generally) with the ALLOCATE procedure. Of course, thereafter the array size is fixed. To dynamically expand an array you generally have to ALLOCATE a larger array, then copy elements across.
If you expect to continue to use your legacy programs then I suggest that the effort of converting to allocatable arrays will be repaid. This is something that I, and I suspect most other Fortran programmers, have done a lot of in the years since Fortran 90 compilers became widely available. One of the ways in which the effort will be repaid is in allowing you to concentrate on other aspects of maintenance. Given the availability of memory on modern computers you need be much less concerned about using such space than the people who wrote the code a generation ago. I expect that the users of the code are trying to tackle much bigger problems than their forefathers too. Allocating arrays will provide some measure of future-proofing.
As for the impact on other parts of the code, give some thought to:
I expect there's a bunch of stuff I've forgotten.
Upvotes: 5