<?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 Re: Memory allocation in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-allocation/m-p/878739#M74635</link>
    <description>Sorry, I was using the wrong terminology. By "bounds checking" I meant that the newer version was checking to make sure memory wasn't corrupted while the older version didn't care as much(basically what you said).&lt;BR /&gt;&lt;BR /&gt;I have tried to adjust the code so use SIZEOF(). The problem is, SIZEOF() keeps returning the value 4, and I know that is not right. Here is the code again(original post formatting wasn't good).&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;     &lt;FONT face="Courier New"&gt;pointer (ptr_desired_stations, desired_stations)&lt;BR /&gt;     structure /STATION_LIST/&lt;BR /&gt;         integer id&lt;BR /&gt;         integer ichan&lt;BR /&gt;         character city*20&lt;BR /&gt;         character state*2&lt;BR /&gt;         character sta_type*1&lt;BR /&gt;         character fill*1&lt;BR /&gt;         logical class_a&lt;BR /&gt;         character offset*1&lt;BR /&gt;      end structure&lt;BR /&gt;      record /STATION_LIST/ desired_stations(*)&lt;/FONT&gt;&lt;BR /&gt;&lt;/PRE&gt;I changed the earlier code to&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="Courier New" size="2"&gt; tmp_size = sizeof(STATION_LIST)&lt;BR /&gt; ptr_desired_stations = malloc(n_des_sta * tmp_size)&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;As I said earlier, when I do this I get "tmp_size = 4". This causes an unrelated error(at least, an error not immediately connected to "ptr_desired_stations"). The line that causes the error is&lt;BR /&gt;&lt;BR /&gt; &lt;FONT face="Courier New" size="2"&gt;write(time_string, 1000) int(hours), &lt;BR /&gt; &amp;amp; int(60*mod(hours, 1.0)),&lt;BR /&gt; &amp;amp; int(60*mod(60*mod(hours, 1.0), 1.0))&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;The error message is&lt;BR /&gt;&lt;BR /&gt;  Insufficient memory to allocate Fortran RTL message buffer, message #41. &lt;BR /&gt;&lt;BR /&gt;This seems to be a memory corruption error. Does SIZEOF() need an instance of STATION_LIST?&lt;BR /&gt;</description>
    <pubDate>Wed, 04 Jun 2008 15:06:38 GMT</pubDate>
    <dc:creator>cdetech</dc:creator>
    <dc:date>2008-06-04T15:06:38Z</dc:date>
    <item>
      <title>Memory allocation</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-allocation/m-p/878734#M74630</link>
      <description>&lt;P&gt;I have a project that I have recently moved from Visual Fortran 6.5 to Intel Fortran 8.1. The code has the following data structure.&lt;/P&gt;&lt;FONT size="2"&gt;&lt;PRE&gt;pointer (ptr_desired_stations, desired_stations)&lt;/PRE&gt;&lt;PRE&gt;structure /STATION_LIST/&lt;/PRE&gt;&lt;PRE&gt;integer id&lt;/PRE&gt;&lt;PRE&gt;integer ichan&lt;/PRE&gt;&lt;PRE&gt;character city*20&lt;/PRE&gt;&lt;PRE&gt;character state*2&lt;/PRE&gt;&lt;PRE&gt;character sta_type*1&lt;/PRE&gt;&lt;PRE&gt;character fill*1&lt;/PRE&gt;&lt;PRE&gt;logical*2 class_a&lt;/PRE&gt;&lt;PRE&gt;character offset*1&lt;/PRE&gt;&lt;PRE&gt;end structure&lt;/PRE&gt;&lt;PRE&gt;record /STATION_LIST/ desired_stations(*)&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face="Arial"&gt;I allocated memory for the object as follows.&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;/FONT&gt;&lt;B&gt;&lt;FONT color="#0000ff" size="2"&gt;if&lt;/FONT&gt;&lt;/B&gt;&lt;FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt; (ptr_desired_stations .ne. 0)&lt;/FONT&gt;&lt;FONT color="#ff0000" size="2"&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;/FONT&gt;&lt;FONT color="#ffffff" size="2"&gt;&amp;amp;&lt;/FONT&gt;&lt;FONT size="2"&gt; &lt;/FONT&gt;&lt;B&gt;&lt;FONT color="#0000ff" size="2"&gt;call&lt;/FONT&gt;&lt;/B&gt;&lt;FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt; report_mem_error_1(routine, pointer_name)&lt;/FONT&gt;&lt;FONT color="#008000" size="2"&gt;&lt;PRE&gt;c&lt;/PRE&gt;&lt;PRE&gt;c Allocate memory&lt;/PRE&gt;&lt;PRE&gt;c&lt;/PRE&gt;&lt;/FONT&gt;&lt;FONT color="#ff0000" size="2"&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;ptr_desired_stations = &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;malloc&lt;/FONT&gt;&lt;FONT size="2"&gt;(n_des_sta * 35)&lt;/FONT&gt;&lt;FONT color="#ff0000" size="2"&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;B&gt;&lt;FONT color="#0000ff" size="2"&gt;if&lt;/FONT&gt;&lt;/B&gt;&lt;FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt; (ptr_desired_stations .eq. 0)&lt;/FONT&gt;&lt;FONT color="#ff0000" size="2"&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;/FONT&gt;&lt;FONT color="#ffffff" size="2"&gt;&amp;amp;&lt;/FONT&gt;&lt;FONT size="2"&gt; &lt;/FONT&gt;&lt;B&gt;&lt;FONT color="#0000ff" size="2"&gt;call&lt;/FONT&gt;&lt;/B&gt;&lt;FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt; report_mem_error(routine, pointer_name, n_des_sta)&lt;/FONT&gt;&lt;FONT color="#ff0000" size="2"&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;B&gt;&lt;FONT color="#0000ff" size="2"&gt;return&lt;/FONT&gt;&lt;/B&gt;&lt;PRE&gt;&lt;B&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;B&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT face="Arial" color="#000000"&gt;The problem happens when I try to free the memory.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;B&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT face="Arial" color="#000000"&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;B&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;P&gt;if&lt;/P&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt; (ptr_desired_stations .eq. 0)&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color="#ff0000" size="2"&gt;&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color="#ffffff" size="2"&gt;&amp;amp;&lt;/FONT&gt;&lt;FONT size="2"&gt; &lt;/FONT&gt;&lt;B&gt;&lt;FONT color="#0000ff" size="2"&gt;call&lt;/FONT&gt;&lt;/B&gt;&lt;FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt; report_mem_error_2(routine, pointer_name)&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color="#ff0000" size="2"&gt;&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;B&gt;&lt;FONT color="#0000ff" size="2"&gt;call&lt;/FONT&gt;&lt;/B&gt;&lt;FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt; &lt;/FONT&gt;&lt;FONT color="#0000ff" size="2"&gt;free&lt;/FONT&gt;&lt;FONT size="2"&gt;(ptr_desired_stations)&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color="#ff0000" size="2"&gt;&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;ptr_desired_stations = 0&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color="#ff0000" size="2"&gt;&lt;P&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;B&gt;&lt;FONT color="#0000ff" size="2"&gt;return&lt;/FONT&gt;&lt;/B&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT color="#000000"&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT face="Arial" color="#000000"&gt;&lt;FONT&gt;I get a "Microsoft Visual C++ Debug library" error that says "DAMAGE: after Normal block(#104659) at 0x06F2B648.  &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT face="Arial" color="#000000"&gt;&lt;FONT&gt;This error does not come up when I compile the program using Visual Fortran 6.5, only with the Intel Fortran 8.1?  &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT face="Arial" color="#000000"&gt;Can someone please tell me why it is coming up(though I believe the size isn't right for the memory allocation, but I've &lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT face="Arial" color="#000000"&gt;tried changing the variabl
e sizes and that didn't work) and why it only comes up in the new compiler(is it a problem that the&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;FONT color="#0000ff" size="2"&gt;&lt;FONT face="Arial" color="#000000"&gt;old compiler misses it)?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Jun 2008 14:43:04 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-allocation/m-p/878734#M74630</guid>
      <dc:creator>cdetech</dc:creator>
      <dc:date>2008-06-03T14:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: Memory allocation</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-allocation/m-p/878735#M74631</link>
      <description>&lt;P&gt;I just noticed that the "logical*2 class_a" should be "logical class_a", which is how it is in the original code. The same error occurred when I&lt;/P&gt;
&lt;P&gt;tried "logical*2 class_a".&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jun 2008 14:48:39 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-allocation/m-p/878735#M74631</guid>
      <dc:creator>cdetech</dc:creator>
      <dc:date>2008-06-03T14:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: Memory allocation</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-allocation/m-p/878736#M74632</link>
      <description>Is this in a subroutine that is called multiple times and the intent is that the pointer to the allocated memory is remembered across the calls? If so, add a SAVE statement for the pointer variable. Otherwise the pointer becomes undefined on exit from the routine.&lt;BR /&gt;</description>
      <pubDate>Tue, 03 Jun 2008 17:53:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-allocation/m-p/878736#M74632</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2008-06-03T17:53:51Z</dc:date>
    </item>
    <item>
      <title>Re: Memory allocation</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-allocation/m-p/878737#M74633</link>
      <description>The problem, it seems, is that I needed to allocate to change the 35 to 37 in the statement "ptr_desired_stations = malloc(n_des_sta * 35)". This makes sense because 37 is the total you get if you add up the default sizess for variables in the structure STATION_LIST. The problem came up only after I compiled in Intel Fortan 8.1. The code always compiled in Compaq Fortran 6.5. Does anyone know if Compaq Fortran 6.5 has default sizes different from Intel Fortran 8.1(I've looked but haven't seen anything)? Or could it be non-rigorous bounds checking?&lt;BR /&gt;</description>
      <pubDate>Tue, 03 Jun 2008 20:33:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-allocation/m-p/878737#M74633</guid>
      <dc:creator>cdetech</dc:creator>
      <dc:date>2008-06-03T20:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: Memory allocation</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-allocation/m-p/878738#M74634</link>
      <description>The sizes haven't changed. You should use SIZEOF() rather than a hardcoded number. My guess is that in the CVF version you were silently corrupting memory and that a different order of memory revealed the problem in Intel Fortran. I don't see how bounds checking is involved.&lt;BR /&gt;&lt;BR /&gt;Version 10.1 is current.&lt;BR /&gt;</description>
      <pubDate>Tue, 03 Jun 2008 21:09:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-allocation/m-p/878738#M74634</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2008-06-03T21:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: Memory allocation</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-allocation/m-p/878739#M74635</link>
      <description>Sorry, I was using the wrong terminology. By "bounds checking" I meant that the newer version was checking to make sure memory wasn't corrupted while the older version didn't care as much(basically what you said).&lt;BR /&gt;&lt;BR /&gt;I have tried to adjust the code so use SIZEOF(). The problem is, SIZEOF() keeps returning the value 4, and I know that is not right. Here is the code again(original post formatting wasn't good).&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;     &lt;FONT face="Courier New"&gt;pointer (ptr_desired_stations, desired_stations)&lt;BR /&gt;     structure /STATION_LIST/&lt;BR /&gt;         integer id&lt;BR /&gt;         integer ichan&lt;BR /&gt;         character city*20&lt;BR /&gt;         character state*2&lt;BR /&gt;         character sta_type*1&lt;BR /&gt;         character fill*1&lt;BR /&gt;         logical class_a&lt;BR /&gt;         character offset*1&lt;BR /&gt;      end structure&lt;BR /&gt;      record /STATION_LIST/ desired_stations(*)&lt;/FONT&gt;&lt;BR /&gt;&lt;/PRE&gt;I changed the earlier code to&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="Courier New" size="2"&gt; tmp_size = sizeof(STATION_LIST)&lt;BR /&gt; ptr_desired_stations = malloc(n_des_sta * tmp_size)&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;As I said earlier, when I do this I get "tmp_size = 4". This causes an unrelated error(at least, an error not immediately connected to "ptr_desired_stations"). The line that causes the error is&lt;BR /&gt;&lt;BR /&gt; &lt;FONT face="Courier New" size="2"&gt;write(time_string, 1000) int(hours), &lt;BR /&gt; &amp;amp; int(60*mod(hours, 1.0)),&lt;BR /&gt; &amp;amp; int(60*mod(60*mod(hours, 1.0), 1.0))&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;The error message is&lt;BR /&gt;&lt;BR /&gt;  Insufficient memory to allocate Fortran RTL message buffer, message #41. &lt;BR /&gt;&lt;BR /&gt;This seems to be a memory corruption error. Does SIZEOF() need an instance of STATION_LIST?&lt;BR /&gt;</description>
      <pubDate>Wed, 04 Jun 2008 15:06:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-allocation/m-p/878739#M74635</guid>
      <dc:creator>cdetech</dc:creator>
      <dc:date>2008-06-04T15:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: Memory allocation</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-allocation/m-p/878740#M74636</link>
      <description>Yes, SIZEOF needs a variable. You caused it to ask for the size of an undeclared variable.&lt;BR /&gt;&lt;BR /&gt;The compiler does no memory range checking other than array and string bounds.&lt;BR /&gt;</description>
      <pubDate>Wed, 04 Jun 2008 17:49:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-allocation/m-p/878740#M74636</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2008-06-04T17:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: Memory allocation</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-allocation/m-p/878741#M74637</link>
      <description>The said error message is [relatively] new in Microsoft's C run time library. The RTL checks whether the "guard" block of memory after the (m)allocated blocks is in the original state and reports the debug message if not.&lt;BR /&gt;&lt;BR /&gt;The problem is indeed in your hard-coded size of the structure (35 or 37, whichever). In reality, it would be 40 -- and that would be returned by SIZEOF(tempStationList). The value of 40 comes as consequence of the "natural alignment" feature of computer architecture -- by default, the processor "likes" that &lt;I&gt;n-&lt;/I&gt;byte variables are aligned on an address divisible by &lt;I&gt;n&lt;/I&gt;. As consequence, the "real" size of structure is a multiply of size of its greatest (non-character) member; that means that you will have 3 "unused" bytes after each member of desired_stations array. Now, you malloc() less memory that you actually use, overwriting its tail in the process.&lt;BR /&gt;&lt;BR /&gt;SEQUENCE keyword (or !DEC$PACK metacommand, I'm not sure if the former applies to STRUCTUREs) should prevent the "natural alignment" to occur, i.e. will "densely pack" the structure members. It will also reduce performance though. As Steve said, best, use SIZEOF with a dummy variable of appropriate type to find out the size.&lt;BR /&gt;</description>
      <pubDate>Thu, 05 Jun 2008 07:46:34 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-allocation/m-p/878741#M74637</guid>
      <dc:creator>Jugoslav_Dujic</dc:creator>
      <dc:date>2008-06-05T07:46:34Z</dc:date>
    </item>
  </channel>
</rss>

