Releases a block of memory (0x49).
#include <dos.h>
#include <errno.h>
unsigned _dos_freemem( unsigned seg );
seg | Block to be released |
The _dos_freemem function uses system call 0x49 to release a block of memory previously allocated by _dos_allocmem. The seg argument is a value returned by a previous call to _dos_allocmem. The freed memory may no longer be used by the application program.
If successful, _dos_freemem returns 0. Otherwise, it returns the DOS error code and sets errno to ENOMEM, indicating a bad segment value (one that does not correspond to a segment returned by a previous _dos_allocmem call) or invalid arena headers.
Standards:None
16-Bit:DOS
32-Bit:None
_dos_allocmem, _dos_setblock, free 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