Quantcast
Channel: Intel® Fortran Compiler
Viewing all articles
Browse latest Browse all 3270

strange memory occupier of allocatable array in custom type in Fortran

$
0
0

I wanna create an allocatable array in custom type as follows:

  1. type cell
  2.    integer(4) :: fn
  3.    integer(4), dimension(:), allocatable :: nd
  4. end type cell
  5. type(cell), dimension(:), allocatable :: elem
  6. allocate(elem(10000))

There is memory occupier ten times more than 10000*4 Bytes before allocating array nd, why?

I thought a custom type might not contains any uncertain array, and modified the code as follows:

  1. type cell
  2.    integer(4) :: fn
  3.    integer(4), pointer :: nd(:)
  4. end type cell
  5. type(cell), dimension(:), allocatable :: elem
  6. allocate(elem(10000))
  7. do i=1,10000
  8.    elem(i)%nd=>cnode(j:j+7)
  9. end do

 where cnode is a target array. The same situation happens, i.g. the memory occupier is  ten times

more than (10000*4+10000*8*4), and why? What should I do to change this?


Viewing all articles
Browse latest Browse all 3270

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>