Allocates a virtual memory block.
#include <vmemory.h>
_vmhnd_t __far _vmalloc( unsigned long size );
size | Bytes to allocate |
The _vmalloc function allocates a virtual memory block of at least size bytes. The actual size of the allocated block may be larger than size bytes to allow the virtual memory manager to operate more efficiently; use _vmsize to find the actual size of the block.
The value returned by _vmalloc is a handle that uniquely identifies the virtual memory block. This value is not an address and cannot be used to access memory directly. The value must be passed to either the _vload or _vlock function to obtain a valid address.
The _vmalloc function returns a handle to the allocated virtual memory block, or _VM_NULL if insufficient memory is available or if the requested block size is too large to load into DOS memory.
Standards:None
16-Bit:DOS
32-Bit:None
/* VMALLOC.C: This program initializes the virtual memory manager with
* _vheapinit and allocates a block of virtual memory with _vmalloc.
* It then frees the memory with _vfree, and terminates the virtual
* memory manager with _vheapterm.
*/
#include <stdio.h>
#include <stdlib.h>
#include <vmemory.h>
void main( void )
{
_vmhnd_t handle;
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 );
}
printf( "Received block of virtual memory.\n" );
_vfree( handle );
_vheapterm();
exit( 0 );
}
Requesting 100 bytes of virtual memory.
Received block of virtual memory.