In this sample program I'm doing the same thing (at least I think so) in two different ways. I'm running this on my Linux pc and monitoring the memory usage with top. Using gfortran I find that in the first way (between "1" and "2") the memory used is 8.2GB, while in the second way (between "2" and "3") the memory usage is 3.0GB. With the Intel compiler the difference is even larger: 10GB versus 3GB. This seems an excessive penalty for using pointers. Why does this happen?
program test implicit none type nodesType integer:: nnodes integer,dimension(:),pointer:: nodes end type nodesType type nodesType2 integer:: nnodes integer,dimension(4):: nodes end type nodesType2 type(nodesType),dimension(:),allocatable:: FaceList type(nodesType2),dimension(:),allocatable:: FaceList2 integer:: n,i n = 100000000 print *, '1' read(*,*) allocate(FaceList(n)) do i=1,n FaceList(i)%nnodes = 4 allocate(FaceList(i)%nodes(4)) FaceList(i)%nodes(1:4) = (/1,2,3,4/) end do print *, '2' read(*,*) do i=1,n deallocate(FaceList(i)%nodes) end do deallocate(FaceList) allocate(FaceList2(n)) do i=1,n FaceList2(i)%nnodes = 4 FaceList2(i)%nodes(1:4) = (/1,2,3,4/) end do print *, '3' read(*,*) end program test
The background is local grid refinement. I chose the linked list to easily add and remove faces. The number of nodes is 4 by default but can become higher depending on the local refinements.