OS/2 codes: How to get size of free physical memory
OS/2 provides APIs to get size of being interested in system memory. For example, DosQuerySysInfo() with QSV_TOTPHYSMEM for total size of physical memory, QSV_TOTRESMEM for total size of system-resident memory, and QSV_TOTAVAILMEM for total size of total available memory for all processes.
However, those indice do not tell us about free physical memory. Actually, any 32-bits APIs do not provide such information at all.
Instead, you can use 16-bits APIs. That is, DosMemAvail(). Here is the prototype of DosMemAvail():
APIRET16 APIENTRY16 Dos16MemAvail( PULONG pulAvailMem )
For details, see https://komh.github.io/os2books/prcp/080_L2_DosMemAvail.html.
VisualAge C++ and Watcom can use this prototype directly. However, unfortunately, gcc does not provide features to call 16-bits functions directly. Instead, you should use thunking. Fortunately, kLIBC provides macros for thunking.
You can call DosMemAvail() on gcc/kLIBC like this:
1 2 3 4 5 6 7 8 9 | USHORT _THUNK_FUNCTION( Dos16MemAvail )(); USHORT Dos16MemAvail( PULONG pulAvailMem ) { return (( USHORT ) ( _THUNK_PROLOG( 4 ); _THUNK_FLAT( pulAvailMem ); _THUNK_CALL( Dos16MemAvail ))); } |
Finally, here is an utility function using Dos16MemAvail() to get size of free physical memory and test program:
- source: https://github.com/komh/os2codes/blob/master/memory/getfreephysmem.c
- header: https://github.com/komh/os2codes/blob/master/memory/getfreephysmem.h
- test: https://github.com/komh/os2codes/blob/master/memory/getfreephysmem-test.c
댓글
댓글 쓰기