_memavl

Description

Returns the size of memory available.

#include <malloc.h> Required only for function declarations  

size_t _memavl( void );

Remarks

The _memavl function returns the approximate size, in bytes, of the memory available for dynamic memory allocation in the near heap (default data segment). The _memavl function can be used with calloc, malloc, or realloc in tiny, small, and medium memory models and with _ncalloc, _nmalloc or _nrealloc in any memory model.

The number returned by the _memavl function may not be the number of contiguous bytes. Consequently, a call to malloc requesting allocation of the size returned by _memavl may not succeed. Use the _memmax function to find the size of the largest available contiguous block of memory.

Return Value

The _memavl function returns the size in bytes as an unsigned integer.

Compatibility

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:None

See Also

calloc functions, _freect, malloc functions, _memmax, realloc functions

Example

/* MEMAVL.C: This program uses _memavl to determine the amount of

* memory available for dynamic allocation. It then uses malloc to

* allocate space for 5,000 long integers and uses _memavl again to

* determine the new amount of available memory.

*/

#include <malloc.h>

#include <stdio.h>

void main( void )

{

long *longptr;

printf( "Memory available before _nmalloc = %u\n", _memavl() );

if( (longptr = _nmalloc( 5000 * sizeof( long ) )) != NULL )

{

printf( "Memory available after _nmalloc = %u\n", _memavl() );

_nfree( longptr );

}

}

Output

Memory available before _nmalloc = 60906

Memory available after _nmalloc = 40390