The use of automatic arrays is a nice feature in Fortran. However, I
don't know of any way to trap out-of-memory errors with automatic
arrays. With allocatable arrays one can test if the allocation is
successful as in:
ALLOCATE(X(n),STAT = STAT)
IF (STAT .NE. 0) THEN
! Fail gracefully
END IF
If any body can allay this particular concern I have with using
automatic arrays I would be grateful.
Thank you,
David.
Michael Metcalf wrote:
>
> ----- Original Message -----
> From: "David Byrne" <[log in to unmask]>
> To: <[log in to unmask]>
> Sent: Monday, April 08, 2002 6:59 PM
> Subject: novice allocatable array question
>
> > I have a memory management question regarding the function attached below.
> > When an allocatable array is allocated within a function, if I fail
> > to deallocate the array before exiting the function, is this a problem?
>
> If you are using a Fortran 90 compiler, yes. In that case you must
> explicitly deallocate the array otherwise your program will leak memory.
> With a Fortran 95 compiler, however, this deallocation is automatic
> ("Fortran 90/95 Explained", Section 6.5.1).
>
> In this particular piece of code, you might prefer to use an automatic array
> instead, as in
>
> integer,dimension(size(prod)) :: temp
>
> That circumvents the problem completely (op. cit. Section 6.4) for what is
> just a temporary, local array.
>
> Hope that helps,
>
> Mike Metcalf
|