C Language and Libraries Help (clang.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
VCNT.C
                                             Up Contents Index Back
─────Run-Time Library───────────────────────────────────────────────────────
 
/* VCNT.C: This program locks a block of virtual memory five times with
 * _vlock, and then unlocks it five times with _vunlock, calling
 * _vlockcnt after each operation to report the number of locks held.
 */
 
#include <stdio.h>
#include <stdlib.h>
#include <vmemory.h>
 
void main()
{
    int i, count;
    _vmhnd_t handle;
    int __far *buffer;
 
    if ( !_vheapinit( 0, _VM_ALLDOS, _VM_XMS | _VM_EMS ) )
    {
        printf( "Could not initialize virtual memory manager. \n" );
        exit( -1 );
    }
 
    if ( (handle = _vmalloc( 100 * sizeof(int) )) == _VM_NULL )
    {
        _vheapterm();
        exit( -1 );
    }
 
    printf( "Block of virtual memory allocated.\n" );
 
    printf( "Locking...\n" );
    for ( i = 0; i < 5; i++ )
    {
        if ( (buffer = (int __far *)_vlock( handle )) == NULL )
        {
            _vheapterm();
            exit( -1 );
        }
 
        count = _vlockcnt( handle );
        printf( "%d locks held.\n", count );
    }
 
    printf("Unlocking...\n" );
    for ( i = 0; i < 5; i++ )
    {
        _vunlock( handle, _VM_CLEAN );
 
        count = _vlockcnt( handle );
        printf( "%d locks held.\n", count );
    }
 
    _vfree( handle );
    _vheapterm();
}
                                    -♦-