This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

return value as an allocatable array


For some reason, my posts are not showing up on comp.lang.fortran . So I
thought I will ask here for help.

Let's say I have a function where the return value is an allocatable
array.

! I am just using this as an example.
! My actual problem is a bit different.
function dot_square(elem_no, A) return (Asqr)
 integer, intent(in) :: elem_no
 real :: A(1:elem_no, 1:elem_no)

 real, allocatable :: Asqr(:,:)

 allocate(Asqr(elem_no, elem_no)
 Asqr = A * A
end function dot_square

It creates an array (for the return value) but never deallocates it.
Will this create a memory leak if I keep repeatedly calling the
function (say in a do loop)?

I want to create the return value as an allocatable array because
sometimes elem_no could be large.

I want to use the function interface instead of calling a subroutine
because I would like to do

Apow4 = dot_square(dot_square(A))


If it does create a memory leak, What is the best way to approach this
problem?

If it helps, I am using gfortran 4.3.2, Fortran 90, Debian Etch.

thanks
raju
-- 
Kamaraju S Kusumanchi
http://www.people.cornell.edu/pages/kk288/
http://malayamaarutham.blogspot.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]