Memory used by extended types

Memory used by extended types

Hello.

 

I have found something weird in the memory used when a derived type extends another but I do not know if there is an explanation for this or if it is just a bug.

The simplified program below works as I would expect only when the default initialization of the Parent type (N = 0) is commented.

When I uncomment the initialization the memory reported by the Windows Task Manager is twice the expected one and after the deallocation not all the memory seems to be released (at the pause statement before the program end).

 

program Test
  type Parent
    integer :: N != 0
  end type
  type, extends(Parent) :: Extended
    real(8) :: M(2000,2000)
  end type
  type(Extended), pointer:: Var
  allocate(Var)
  Var%M = 0d0
  pause
  deallocate(Var)
  pause
end program Test

 

Thanks in advance.

 

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Because there are initial values in the declaration, a static template (if you will) is created of the extended derived type, with all the initial values filled in.

That template is used to initialize any objects that are created of the derived type.

So, yes, there is static memory used to hold the fully initialized type, and no, that's not released on a deallocate.

                    --Lorri

Since array component 'M' of the extended type is so large, when you initialise N it creates a huge initialised data section, compared to the version which doesn't have that initialisation:

************************VERSION WITH INITIALISATION*****************************

C:\ISN_Forums\U507197>dumpbin /headers U507197.exe |grep 'size of initialized data'
         1ED0800 size of initialized data

 

*********************VERSION WITHOUT INITIALISATION*****************************

C:\ISN_Forums\U507197>dumpbin /headers U507197-no-init-N.exe |grep 'size of initialized data'
           3C400 size of initialized data

 

Patrick

Understood!. Thanks for your help.

The problem I face is that I derive many different objects from a base object with default initializations, so all these objects will create a static 'template' consuming a non negligible amount of memory just because the base object has a default initialization.

Knowing that, I can cope with this just avoiding the default initialization and creating a 'constructor' routine for the base object.

Is this part of the Fortran standard or it is just a feature of the Intel implementation?

Jose A.

The standard doesn't involve itself in implementation details such as this. Creating a constructor function may be the best choice for you.

Steve

Login to leave a comment.