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:


댓글

이 블로그의 인기 게시물

토렌트: < 왕좌의 게임 > 시즌 1 ~ 시즌 8 완결편 마그넷

토렌트: < 스타워즈 > Ep.1 ~ Ep.6 마그넷

토렌트: NGC < 코스모스 > 우리말 더빙 전편(1편~13편) 마그넷