Hi,
I am trying to figure out the memory usage of a linked list in fortran 90. I use the following simple test code.
program test_sub
implicit none
type:: mytype
integer :: ij(2)
type(mytype), pointer :: next
end type mytype
integer :: k, n
type(mytype), pointer :: head, tail, item
n=1e7 !---> length of the list
nullify(head, tail)
do k=1,n
nullify(item)
allocate(item)
item%ij=1
if (k==1) then
head=>item
tail=>item
else
tail%next=>item
tail=>item
end if
end do
stop
end program test_sub
I expect 16 byte per node (8 byte for the integers and 8 for the pointer) and ~150mb memory usage in total. However when I check the usage through the system using ‘top’ command, I see 764mb. If I increase the length of the list to 1e8, memory usage is 7.5gb while I expect it to be 1.5gb. Am I doing something stupid in this code? Or my calculations are wrong? I am using pgf90 version 7.0 on a linux 64 bit machine without any flags. Can anybody help me out?
Thank you for your time
Onur Bakir