Virtual memory is a facility for accessing storage beyond the 640K of memory available to DOS. Microsoft C/C++ provides a virtual memory manager through a set of functions in the run-time library. This memory manager uses expanded memory (EMS), extended memory (XMS), and disk storage to simulate a heap of nearly unlimited size. By using this virtual heap, your program can access those three memory resources through a single interface and acquire far more memory than is available from the traditional malloc family of functions.
Note that the virtual memory functions are only available for 16-bit DOS programs. Windows programs and 32-bit programs do not need to use these functions.
The virtual memory manager works by copying blocks of virtual memory into DOS memory when they're in use, and swapping them out to auxiliary storage when they're not. In general, a program that uses the virtual memory manager must perform the following steps:
Initialize the virtual memory manager by calling _vheapinit
Allocate virtual memory blocks as needed by calling _vmalloc
Load or lock virtual memory blocks into the DOS address space in order to access their contents, using _vload and _vlock
Unlock virtual memory blocks when they're not being accessed by calling _vunlock
Free virtual memory blocks when they're no longer needed by calling _vfree
Terminate the virtual memory manager by calling _vheapterm
The following sections describe these steps in more detail.