- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The standard doesn't involve itself in implementation details such as this. Creating a constructor function may be the best choice for you.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page