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.
VRSIZE.C
                                             Up Contents Index Back
─────Run-Time Library───────────────────────────────────────────────────────
 
/* VRSIZE.C: This program allocates a block of virtual memory with
 * _vmalloc and uses _vmsize to display the size of that block. Next,
 * it uses _vrealloc to expand the amount of virtual memory and calls
 * _vmsize again to display the new amount of memory allocated.
 */
 
#include <stdio.h>
#include <stdlib.h>
#include <vmemory.h>
 
void main()
{
    _vmhnd_t handle;
    unsigned long block_size;
 
    if ( !_vheapinit( 0, _VM_ALLDOS, _VM_XMS | _VM_EMS ) )
    {
        printf( "Could not initialize virtual memory manager.\n" );
        exit( -1 );
    }
 
    printf( "Requesting 100 bytes of virtual memory.\n" );
    if ( (handle = _vmalloc( 100 )) == _VM_NULL )
    {
        _vheapterm();
        exit( -1 );
    }
 
    block_size = _vmsize( handle );
    printf( "Received %d bytes of virtual memory.\n", block_size );
 
    printf( "Resizing block to 200 bytes. \n" );
    if ( (handle = _vrealloc( handle, 200 )) == _VM_NULL )
    {
        _vheapterm();
        exit( -1 );
    }
 
    block_size = _vmsize( handle );
    printf( "Block resized to %d bytes.\n", block_size );
 
    _vfree( handle );
    _vheapterm();
}
                                    -♦-