Jane and I have written a small set of examples using the Windows and Linux memory api’s.
Here is the main program for one of examples using the Windows memory api’s.
#####
include ‘integer_kind_module.f90’
include ‘display_with_commas_module.f90’
include ‘memory_module_windows.f90’
program ch4401
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 ch4401
#####
Here is the main program for one of examples using the Linux memory api’s.
#####
include ‘integer_kind_module.f90’
include ‘ch4402_memory_module_linux.f90’
include ‘display_with_commas_module.f90’
program ch4402
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 ch4402
#####
The complete source code can be found at our web sites.
A tar file is available on this site of all of the source code.
Here is some sample out from the Intel ifx compiler under Windows
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2026
.0.0 Build 20260331
Memory usage 13 %
Total physical 137,131,782,144
Available physical 117,936,807,936
Total page file 157,532,876,800
Available page file 137,739,665,408
Total virtual 140,737,488,224,256
Available virtual 140,733,140,942,848
Here is some sample output from the gfortran compiler under Linux.
ian@dell-5820:/mnt/c/document/fortran/4th_edition_update/examples> ./ch4402_gfortran.out
GCC version 15.2.1 20260202
Total ram 84329304064 84,329,304,064
Free ram 83532967936 83,532,967,936
Share ram 3108864 3,108,864
Buffer ram 44003328 44,003,328
Total swap 21474836480 21,474,836,480
Free swap 21474836480 21,474,836,480
Total high 0 0
Free high 0 0
ian@dell-5820:/mnt/c/document/fortran/4th_edition_update/examples>
examples ch4405.f90 (Windows) and ch4406.f90 (Linux) illustrate checking memory availability and terminating gracefully.