Difference between automatic arrays on the heap and allocatable arrays

It is possible on both Windows and Linux to make memory queries.

Here is the output from a program on a Windows platform, that uses a windows api.

Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel
(R) 64, Version 2021.8.0 Build 20221119_000000
Memory usage 11 %
Total physical 68,412,305,408
Available physical 60,602,290,176
Total page file 78,612,852,736
Available page file 69,079,638,016
Total virtual 140,737,488,224,256
Available virtual 140,733,141,639,168

Here is the equivalent on Linux.

ian@dell-5820:/mnt/c/document/fortran/4th_edition_update> ./ch4304_ifort_icx.out
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel
(R) 64, Version 2021.8.0 Build 20221119_000000
Total ram 68412305408 68,412,305,408
Free ram 60622983168 60,622,983,168
Share ram 0 0
Buffer ram 0 0
Total swap 127830847488 127,830,847,488
Free swap 127825920000 127,825,920,000
Total high 142548992 142,548,992
Free high 278528 278,528
ian@dell-5820:/mnt/c/document/fortran/4th_edition_update>

Jane and I used the C interop facilities to call the relevent C routines from Fortran.

Here is the Windows Fortran source

include ‘integer_kind_module.f90’
include ‘display_with_commas_module.f90’
include ‘memory_module_windows.f90’

program ch4303

use iso_fortran_env
use memory_module_windows
use display_with_commas_module

print *,compiler_version()
print *,’ Memory usage ‘,MemoryLoad(),’ %’
print *,’ Total physical ‘,display_with_commas(TotalPhysical())
print *,’ Available physical ‘,display_with_commas(AvailablePhysical())
print *,’ Total page file ‘,display_with_commas(TotalPageFile())
print *,’ Available page file ‘,display_with_commas(AvailablePageFile())
print *,’ Total virtual ‘,display_with_commas(TotalVirtual())
print *,’ Available virtual ',display_with_commas(AvailableVirtual())

end program ch4303

Here is the Linux Fortran source.

include ‘integer_kind_module.f90’
include ‘ch4304_memory_module_linux.f90’
include ‘display_with_commas_module.f90’

program ch4304

use iso_fortran_env
use memory_module_linux
use display_with_commas_module

print *,compiler_version()
print *,’ Total ram ‘,totalram() ,’ ‘,display_with_commas(totalram())
print *,’ Free ram ‘,freeram() ,’ ‘,display_with_commas(freeram())
print *,’ Share ram ‘,sharedram() ,’ ‘,display_with_commas(sharedram())
print *,’ Buffer ram ‘,bufferram() ,’ ‘,display_with_commas(bufferram())
print *,’ Total swap ‘,totalswap() ,’ ‘,display_with_commas(totalswap())
print *,’ Free swap ‘,freeswap() ,’ ‘,display_with_commas(freeswap())
print *,’ Total high ‘,totalhigh() ,’ ‘,display_with_commas(totalhigh())
print *,’ Free high ‘,freehigh() ,’ ',display_with_commas(freehigh())
end program ch4304

We can provide links to the complete set of source files used if people are interested.

We had the use of a Mac for a while, but couldn’t find any way of doing it on
that platform.