Returns the number of times a virtual memory block was locked.
#include <vmemory.h>
unsigned int __far _vlockcnt( _vmhnd_t handle );
handle | Handle to previously allocated virtual memory block |
The _vlockcnt function returns the number of times a virtual memory block has been locked. The argument handle points to a virtual memory block previously allocated through a call to _vmalloc or _vrealloc. Use the _vlockcnt function to ensure that a block is unlocked before it is freed (using _vfree).
The _vlockcnt function returns the number of locks held on the specified virtual memory block.
Standards:None
16-Bit:DOS
32-Bit:None
/* 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( void )
{
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();
exit( 0 );
}
Block of virtual memory allocated.
Locking...
1 locks held.
2 locks held.
3 locks held.
4 locks held.
5 locks held.
Unlocking...
4 locks held.
3 locks held.
2 locks held.
1 locks held.
0 locks held.