Re: A problem about Fortran pointers
- From: Gordon Sande <g.sande@xxxxxxxxxxxxxxxx>
- Date: Sat, 30 Jun 2007 20:18:43 GMT
On 2007-06-30 14:41:58 -0300, yaqi <yaqiwang@xxxxxxxxx> said:
Dear all,
I have a small piece of code which is an abstract of what I am planing
to do.
---------------------------------------------------------------------------
program testmemory
integer, parameter :: big = 10000000
type type1
integer, pointer :: a(:)
end type
type type2
type(type1), pointer :: b(:)
end type
type(type2) var
allocate(var%b(big))
! first pause point
call pauseit
do i=1,big
nullify(var%b(i)%a)
enddo
! second pause point
call pauseit
do i=1,big
allocate(var%b(i)%a(1))
enddo
! last pause point
call pauseit
end
subroutine pauseit
write(*,*) 'hit enter to continue'
read(*,'(a)') d
return
end subroutine
-----------------------------------------------------------------------------
Basically I am trying to use the function of array of pointers. After
reaching the first pause point, I noticed the memory cost is about
320MB, which is much larger than what I expected! I thought if a
pointer costs 4B, the total memory cost should be 40MB. Obviously I am
wrong here.
You seem to be thinking C on pointers as only raw hardware addresses.
Instead think of a Fortran pointer as a descriptor that has things
like bounds, strides etc as well as a raw hardware pointer. 32B
ain't bad for a descriptor. The descriptor has all the useful things
needed to make pointers rather painless in use.
I am using Compaq Visual Fortran Professional Edition 6.6.C.
The second step does not cost more memory but CPU time. And be caution
on the last step, on my laptop, it will keep eating memory, which is
another thing I can not understand!
Does anybody have idea on what is happening? I feel a little bit
frustrated now :(
Thanks
.
- References:
- A problem about Fortran pointers
- From: yaqi
- A problem about Fortran pointers
- Prev by Date: Re: Need Help: compiling old Fortran program
- Next by Date: Re: Need Help: compiling old Fortran program
- Previous by thread: A problem about Fortran pointers
- Index(es):