Name
_memavl - Returns size of available memory.
Syntax
#include <malloc.h>
size_t _memavl(void)
Description
The _memavl function returns the approximate size, in bytes,
of the memory available for dynamic memory allocation in the
default data segment (that is, near-heap allocations). The
_memavl function can be used with calloc, malloc, or realloc
in small- and medium-memory models.
The number of bytes returned by the _memavl function may not
be contiguous bytes. As a result, a call to malloc
requesting an allocation of the size returned by _memavl may
not succeed. Use the _memmax function to find the size of
contiguous memory available.
Return Value
The _memavl function returns the size in bytes as an
unsigned integer.
See Also
calloc(S), _freect(DOS), malloc(DOS), realloc(S)
Example
#include <malloc.h>
main()
{
long *longptr;
printf("Memory available before malloc = %u\n",
_memavl());
longptr = (long*)malloc(5000*sizeof(long));
printf("Memory available after malloc = %u\n",
_memavl());
}
Sample output:
Memory available before malloc = 61383
Memory available after malloc = 40959
This program uses _memavl to determine the amount of
available memory. It then uses malloc to allocate space for
5,000 long integers and uses _memavl again to determine the
new amount of available memory.
(printed 6/18/89)