Changes the size of a memory segment, using system call 0x4A.
#include <dos.h>
unsigned _dos_setblock( unsigned size, unsigned seg, unsigned *maxsize );
size | New segment size | |
seg | Target segment | |
maxsize | Maximum-size buffer |
The _dos_setblock routine uses system call 0x4A to change the size of seg, previously allocated by _dos_allocmem, to size paragraphs. If the request cannot be satisfied, the maximum possible segment size is copied to the buffer pointed to by maxsize.
The function returns 0 if successful. If the call fails, it returns the DOS error code and sets errno to ENOMEM, indicating a bad segment value was passed. A bad segment value is one that does not correspond to a segment returned from a previous _dos_allocmem call, or one that contains invalid arena headers.
Standards:None
16-Bit:DOS
32-Bit:None
_dos_allocmem, _dos_freemem, realloc functions
/* DALOCMEM.C: This program allocates 20 paragraphs of memory, increases
* the allocation to 40 paragraphs, and then frees the memory space.
*/
#include <dos.h>
#include <stdio.h>
void main( void )
{
unsigned segment;
unsigned maxsize;
/* Allocate 20 paragraphs */
if( _dos_allocmem( 20, &segment ) != 0 )
printf( “allocation failed\n” );
else
printf( “allocation successful\n” );
/* Increase allocation to 40 paragraphs */
if( _dos_setblock( 40, segment, &maxsize ) != 0 )
printf( “allocation increase failed\n” );
else
printf( “allocation increase successful\n” );
/* Free memory */
if( _dos_freemem( segment ) != 0 )
printf( “free memory failed\n” );
else
printf( “free memory successful\n” );
}
allocation successful
allocation increase successful
free memory successful