_dos_allocmem

Description

Allocates a block of memory, using DOS service 0x48.

#include <dos.h>

#include <errno.h>

unsigned _dos_allocmem( unsigned size, unsigned *seg );

size Block size to allocate  
seg Return buffer for segment descriptor  

Remarks

The _dos_allocmem function uses DOS service 0x48 to allocate a block of memory size paragraphs long. (A paragraph is 16 bytes.) Allocated blocks are always paragraph aligned. The segment descriptor for the initial segment of the new block is returned in the word that seg points to. If the request cannot be satisfied, the maximum possible size (in paragraphs) is returned in this word instead.

Return Value

If successful, the _dos_allocmem returns 0. Otherwise, it returns the DOS error code and sets errno to ENOMEM, indicating insufficient memory or invalid arena (memory area) headers.

Compatibility

Standards:None

16-Bit:DOS

32-Bit:None

See Also

_alloca, calloc functions, _dos_freemem, _dos_setblock, _halloc, malloc functions

Example

/* 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" );

}

Output

allocation successful

allocation increase successful

free memory successful