Initializing the Virtual Memory Manager

You initialize the virtual memory manager by calling _vheapinit and passing it three arguments: the minimum amount of DOS memory that must be available for the virtual memory manager to be installed (in 16-byte paragraphs), the maximum amount of DOS memory that it can use (in paragraphs), and flags indicating which types of auxiliary storage it can use to hold swapped-out blocks.

The virtual memory manager may round up the minimum value you specify. If, after rounding, the minimum amount of memory is not available, the virtual memory manager is not installed. The virtual memory manager needs several kilobytes in order to function effectively.

If you want the virtual memory manager to use as much DOS memory as it can, specify _VM_ALLDOS as the second argument. You should not specify this if your program is performing tasks that require a lot of free memory, such as spawning a process.

To specify the types of auxiliary storage that the virtual memory manager can use, use the flags _VM_EMS, _VM_XMS, or _VM_DISK. One or more of these flags can be specified if they are joined by the bitwise-OR operator ( | ). To use all three types, specify _VM_ALLSWAP. If not all forms of storage are available when the program runs, the virtual memory manager uses what is available.

A typical call to _vheapinit looks like this:

if ( !_vheapinit( 0, _VM_ALLDOS, _VM_ALLSWAP ) )

{

/* initialization failed - perform error handling */

}

else

/* continue with normal program execution */

This call to _vheapinit specifies that the virtual memory manager should attempt to install itself no matter how little memory is available, though the attempt may fail if insufficient memory is available. This call also specifies that the virtual memory manager should use as much memory as is available, and that it should use all forms of auxiliary storage.

When your program is done using virtual memory, it must call the _vheapterm function to terminate the virtual memory manager.

Note:

If your program ends without calling _vheapterm, various system memory resources may not be available to subsequent programs.

You can initialize and terminate the virtual memory manager as many times as you want within your program.