Reallocates a virtual memory block.
#include <vmemory.h>
_vmhnd_t __far _vrealloc( _vmhnd_t handle, unsigned long size );
handle | Handle to previously allocated virtual memory block | |
size | New size in bytes |
The _vrealloc function changes the size of a virtual memory block. If handle is _VM_NULL, _vrealloc behaves in the same way as _vmalloc and allocates a new block of size bytes. If handle is not _VM_NULL, it must point to a virtual memory block previously allocated through a call to _vmalloc or _vrealloc.
The size argument gives the new size of the block, in bytes. The size of the 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 contents of the block are unchanged up to the shorter of the new and old sizes, although the new block may be in a different location.
The _vrealloc functions returns a handle to the reallocated (and possibly moved) virtual memory block.
The return value is _VM_NULL if the size specified is zero and the handle argument is not _VM_NULL. In this case, the original block is freed.
The return value is also _VM_NULL if there is not enough available memory to expand the block to the requested size, if the requested block size is too large to load into DOS memory, or if the given handle is still locked. In these cases, the original block is still valid.
Standards:None
16-Bit:DOS
32-Bit:None
/* 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( void )
{
_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();
exit( 0 );
}
Requesting 100 bytes of virtual memory.
Received 100 bytes of virtual memory.
Resizing block to 200 bytes.
Block resized to 200 bytes.