<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Thank you for the quick in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-array-in-a-type-who-will-deallocate-memory/m-p/939556#M89651</link>
    <description>Thank you for the quick responce,

I do have some more questions.

I am a mechanical engineer (not a "real" programmer) with C/C++ background.
So this copy mechanism astonishes me!
I can assume that the compiler always knows the size of the input variable even when it is a type with dynamicaly allocated members.
Am I correct?

One more question has to do with the stack size.
Local variables with dynamicaly allocated members are allocated on the stack or on the heap? Will I have problems with the size of the stack in subroutine test_copy_my_type_2 if the size of the input variable is too big to fit?

Finally as I noticed in this thread &lt;A href="http://software.intel.com/en-us/forums/topic/363691" target="_blank"&gt;http://software.intel.com/en-us/forums/topic/363691&lt;/A&gt; there is a problem with the deallocation of dynamicaly allocated nested types within a type that "you expect problem to be fixed in Update 4 (late June)."

Does this means that until it is fixed I have to manualy deallocate all dynamicaly allocated nested types before their parent is deallocated?

Thank you again for the responce

Emmanuil Tsagarakis</description>
    <pubDate>Wed, 24 Apr 2013 06:29:50 GMT</pubDate>
    <dc:creator>mtsagara</dc:creator>
    <dc:date>2013-04-24T06:29:50Z</dc:date>
    <item>
      <title>Allocatable array in a type - who will deallocate memory?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-array-in-a-type-who-will-deallocate-memory/m-p/939554#M89649</link>
      <description>Hello,

could you please help me with this code.
I have a type that contains an allocatable array. I want to copy an intent(in) variable of that type in a subroutine to a either a local within the subroutine as in test_copy_my_type_2 or to a module private variable as in test_copy_my_type_1.

I have two questions.

1) how do these statements work?

    my_private_type = input_type;

    temp_my_type = input_type;

    Do they perform a value copy or just pointer assigments?

2) If it is a value copy, do I have to free the allocated memory manually as in  test_copy_my_type_1?

Thank you in advance
Emmanuil Tsagarakis
 
    module test_allocatable_types
    implicit none 

    type my_type
        integer(4)                              num_values;
        real(8), dimension(:), allocatable ::   arr_values;
    end type    
    
    type (my_type), private:: my_private_type;
        
    contains 
    
    subroutine test_copy_my_type_1(input_type)
        implicit none;
        type (my_type), intent (in):: input_type;

        my_private_type = input_type;

        if (allocated(my_private_type%arr_values)) deallocate(my_private_type%arr_values);
        
    end subroutine
    
    subroutine test_copy_my_type_2(input_type)
        implicit none;
        type (my_type), intent (in):: input_type;
        type (my_type) temp_my_type;

        temp_my_type = input_type;

    end subroutine
    
    end module test_allocatable_types  

    
    program main
    use test_allocatable_types;
    implicit none
    type (my_type) t;

    t%num_values = 1000000;
    allocate(t%arr_values(t%num_values));
    call test_copy_my_type_1(t);
    call test_copy_my_type_2(t);
    deallocate(t%arr_values);
    
    end program</description>
      <pubDate>Tue, 23 Apr 2013 09:35:18 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-array-in-a-type-who-will-deallocate-memory/m-p/939554#M89649</guid>
      <dc:creator>mtsagara</dc:creator>
      <dc:date>2013-04-23T09:35:18Z</dc:date>
    </item>
    <item>
      <title>If you copy to a local</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-array-in-a-type-who-will-deallocate-memory/m-p/939555#M89650</link>
      <description>&lt;P&gt;If you copy to a local variable in a procedure that has not been given the SAVE attribute, then the allocatable components will be automatically deallocated when the procedure returns. If you copy to a module variable, it will not get deallocated at all (until all storage is freed on program exit.)&lt;/P&gt;
&lt;P&gt;So in your example, the copy made in test_copy_my_type_1 will not get deallocated. while the copy made in test_copy_my_type_2 will get deallocated as soon as that routine returns to the caller.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2013 19:24:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-array-in-a-type-who-will-deallocate-memory/m-p/939555#M89650</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2013-04-23T19:24:45Z</dc:date>
    </item>
    <item>
      <title>Thank you for the quick</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-array-in-a-type-who-will-deallocate-memory/m-p/939556#M89651</link>
      <description>Thank you for the quick responce,

I do have some more questions.

I am a mechanical engineer (not a "real" programmer) with C/C++ background.
So this copy mechanism astonishes me!
I can assume that the compiler always knows the size of the input variable even when it is a type with dynamicaly allocated members.
Am I correct?

One more question has to do with the stack size.
Local variables with dynamicaly allocated members are allocated on the stack or on the heap? Will I have problems with the size of the stack in subroutine test_copy_my_type_2 if the size of the input variable is too big to fit?

Finally as I noticed in this thread &lt;A href="http://software.intel.com/en-us/forums/topic/363691" target="_blank"&gt;http://software.intel.com/en-us/forums/topic/363691&lt;/A&gt; there is a problem with the deallocation of dynamicaly allocated nested types within a type that "you expect problem to be fixed in Update 4 (late June)."

Does this means that until it is fixed I have to manualy deallocate all dynamicaly allocated nested types before their parent is deallocated?

Thank you again for the responce

Emmanuil Tsagarakis</description>
      <pubDate>Wed, 24 Apr 2013 06:29:50 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-array-in-a-type-who-will-deallocate-memory/m-p/939556#M89651</guid>
      <dc:creator>mtsagara</dc:creator>
      <dc:date>2013-04-24T06:29:50Z</dc:date>
    </item>
    <item>
      <title>Quote:mtsagara wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-array-in-a-type-who-will-deallocate-memory/m-p/939557#M89652</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;mtsagara wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Thank you for the quick responce,&lt;/P&gt;
&lt;P&gt;I do have some more questions.&lt;/P&gt;
&lt;P&gt;I am a mechanical engineer (not a "real" programmer) with C/C++ background.&lt;BR /&gt; So this copy mechanism astonishes me!&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;If you are familiar with C++, the memory management aspect of allocatable arrays is similar to the memory management aspects of using a std::vector class member.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;I can assume that the compiler always knows the size of the input variable even when it is a type with dynamicaly allocated members.&lt;BR /&gt; Am I correct?&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;The compiler may not know at compile time, but at runtime the (perhaps compiler supplied) internals of your program will know the size of the component.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;One more question has to do with the stack size.&lt;BR /&gt; Local variables with dynamicaly allocated members are allocated on the stack or on the heap? Will I have problems with the size of the stack in subroutine test_copy_my_type_2 if the size of the input variable is too big to fit?&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Note that stack/heap etc are implementation details.&amp;nbsp; Typically a local variable either goes on the stack or has space statically alloted for it as part of the loading of the executable image, depending on compiler options and procedure and variable attributes.&amp;nbsp; But for allocatable components the memory alloted for that variable only contains a descriptor that descripts^h^h^hbes where the data for the component is and things like its bounds and extent.&amp;nbsp; The data for the component is usually stored on the heap.&amp;nbsp; Again - this is similar to typical implementation of a std::vector in C++.&lt;/P&gt;
&lt;P&gt;Operations on that component may then require temporary workspace on the stack - that can sometime cause issues.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Finally as I noticed in this thread &lt;A href="http://software.intel.com/en-us/forums/topic/363691"&gt;http://software.intel.com/en-us/forums/topic/363691&lt;/A&gt; there is a problem with the deallocation of dynamicaly allocated nested types within a type that "you expect problem to be fixed in Update 4 (late June)."&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Does this means that until it is fixed I have to manualy deallocate all dynamicaly allocated nested types before their parent is deallocated?&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;
&lt;P&gt;That problem was to do with finalization - the calling of a programmer supplied procedure tied to the type of the component before the component was deallocated - a bit like a C++ destructor.&amp;nbsp; The actual deallocation of the component still happened, if I recall correctly.&amp;nbsp; For non-polymorphic stuff (variables and components declared with TYPE) I'm not aware of any current bugs.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2013 21:28:06 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Allocatable-array-in-a-type-who-will-deallocate-memory/m-p/939557#M89652</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2013-04-24T21:28:06Z</dc:date>
    </item>
  </channel>
</rss>

