◄Up► ◄Contents► ◄Index► ◄Back► ─────Run-Time Library─────────────────────────────────────────────────────── /* VLOCK.C: This program locks a block of virtual memory using _vlock, * writes to it, loads in a new block with _vload, and then verifies * that the contents of the locked block are still accessible. It then * unlocks the block with _vunlock. */ #include <stdio.h> #include <stdlib.h> #include <vmemory.h> void main() { 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 *)_vlock( handle1 )) == NULL ) { _vheapterm(); exit( -1 ); } printf( "buffer1 locked: valid until unlocked.\n" ); for ( i = 0; i < 100; i++ ) // write to buffer1 buffer1[i] = i; if ( (buffer2 = (int __far *)_vload( handle2, _VM_DIRTY )) == NULL ) { _vheapterm(); exit( -1 ); } printf( "buffer2 loaded. buffer 1 still valid.\n" ); flag = 0; for ( i = 0; i < 100; i++ ) if ( buffer1[i] != i ) flag = 1; if ( !flag ) printf( "contents of buffer1 verified.\n" ); _vunlock( handle1, _VM_DIRTY ); _vfree( handle1 ); _vfree( handle2 ); _vheapterm(); } -♦-