Loads a virtual memory block into DOS memory.
#include <vmemory.h>
void __far *__far _vload( _vmhnd_t handle, int dirty );
handle | Handle to previously allocated virtual memory block | |
dirty | Flag indicating whether the block should be written out or discarded when swapping occurs |
The _vload function loads a virtual memory block into DOS memory and returns a far pointer to it. The argument handle points to a virtual memory block previously allocated through a call to _vmalloc or _vrealloc.
The block of memory is not locked and may be swapped out if the virtual memory manager needs the memory. Consequently, the pointer returned by _vload is valid only until the next call to the virtual memory manager.
The dirty flag indicates whether the block of memory should be written out or discarded when swapping occurs. It can have one of the following values:
Value | Meaning |
_VM_CLEAN | Discard contents of block when swapping occurs |
_VM_DIRTY | Write contents of block to auxiliary memory when swapping occurs |
The _vload function returns a far pointer to DOS memory if the virtual memory block is successfully loaded. If insufficient DOS memory is available, _vload returns NULL.
Standards:None
16-Bit:DOS
32-Bit:None
/* VLOAD.C: This program loads a block of virtual memory with _vload,
* writes to it, and loads in a new block. It then reloads the first block
* and verifies that its contents haven't changed.
*/
#include <stdio.h>
#include <stdlib.h>
#include <vmemory.h>
void main( void )
{
int i, flag;
_vmhnd_t handle1,
handle2;
int __far *buffer1;
int __far *buffer2;
if ( !_vheapinit( 0, _VM_ALLDOS, _VM_XMS | _VM_EMS ) )
{
printf( "Could not initialize virtual memory manager. \n" );
exit( -1 );
}
if ( ( (handle1 = _vmalloc( 100 * sizeof(int) )) == _VM_NULL ) ||
( (handle2 = _vmalloc( 100 * sizeof(int) )) == _VM_NULL ) )
{
_vheapterm();
exit( -1 );
}
printf( "Two blocks of virtual memory allocated.\n" );
if ( (buffer1 = (int __far *)_vload( handle1, _VM_DIRTY )) == NULL )
{
_vheapterm();
exit( -1 );
}
printf( "buffer1 loaded: valid until next call to VM manager.\n" );
for ( i = 0; i 100; i++ ) /* write to buffer1 */
buffer1[i] d= i;
if ( (buffer2 = (int __far *)_vload( handle2, _VM_DIRTY )) == NULL )
{
_vheapterm();
exit( -1 );
}
printf( "buffer2 loaded. buffer 1 no longer valid.\n" );
if ( (buffer1 = (int __far *)_vload( handle1, _VM_CLEAN )) == NULL )
{
_vheapterm();
exit( -1 );
}
printf( "buffer1 reloaded.\n" );
flag = 0;
for ( i = 0; i 100; i++ )
if ( buffer1[i] != i )
flag = 1;
if ( !flag )
printf( "Contents of buffer1 verified.\n" );
_vfree( handle1 );
_vfree( handle2 );
_vheapterm();
exit( 0 );
}
Two blocks of virtual memory allocated.
buffer1 loaded: valid until next call to VM manager.
buffer2 loaded. buffer 1 no longer valid.
buffer1 reloaded.
Contents of buffer1 verified.