A problem about Fortran pointers



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.

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

.