dos12.hlp (Table of Contents; Topic list)
DosMemAvail (1.2)
Function Group  Overview                          Up Next Previous
────────────────────────────────────────────────────────────────────────────
 
#define INCL_DOSMEMMGR
 
USHORT DosMemAvail(pulAvailMem)
PULONG pulAvailMem;    /* pointer to variable for available memory */
 
The DosMemAvail function retrieves the size of the largest consecutive block
of free memory available when the function is called. This function does not
cause segments to be moved, swapped, or discarded.
 
Parameter    Description
────────────────────────────────────────────────────────────────────────────
 
pulAvailMem  Points to the variable that receives the size (in bytes) of the
             largest free block of memory.
 
Return Value
 
The return value is zero if the function is successful. Otherwise, it is an
error value.
 
Comments
 
Since other processes may allocate and free memory at any time, the size of
the largest free block can be expected to change.
 
The DosMemAvail function returns only the amount of memory currently
available without swapping or moving. More memory can be allocated than
indicated by the DosMemAvail function──when necessary, the system moves
memory, swaps memory, or discards unlocked memory to meet memory-allocation
requests.
 
Example
 
This example calls DosMemAvail to determine the amount of available memory.
It then allocates one third of that memory and allows for reallocation of up
to ten 64K segments.
 
#define SEGSIZE (64L * 1024L)
LONG lAvail;
SEL sel;
 
DosMemAvail(&lAvail);               /* gets amount of current memory  */
lAvail /= 3L;                       /* calculates one third of memory */
DosAllocHuge((USHORT) (lAvail / SEGSIZE), /* number of segments       */
    (USHORT) (lAvail % SEGSIZE),          /* size of last segment     */
    &sel,                                 /* address of selector      */
    10,                             /* allows reallocation up to 640K */
    SEG_NONSHARED);                 /* sharing flag                   */
 
See Also
 
DosAllocHuge