Name
_freect - Counts available dynamic memory.
Syntax
#include <malloc.h>
unsigned int _freect(size)
size_t size;
Description
The _freect function tells you how much memory is available
for dynamic memory allocation. It does so by returning the
approximate number of times your program can call malloc to
allocate an item size bytes long in the default data
segment.
Return Value
The _freect function returns the number of calls as an
unsigned integer.
See Also
calloc(S), _expand(DOS), malloc(DOS), _memavl(DOS),
_msize(DOS), realloc(S)
Example
#include <malloc.h>
main()
{
int i;
/* First report on the free space: */
printf("Approximate # of times program can call");
printf(" malloc \n to allocate a single integer"),
printf(" = %u\n", _freect(sizeof(int)));
/* Allocate space for 1000 integers: */
for (i = 0; i < 1000; ++i)
malloc(sizeof(int));
/* Report again on the free space: */
printf("Approximate # of times program can call");
printf(" malloc\n to allocate a single integer")
printf(" = %u\n", _freect(sizeof(int)));
}
Sample output:
Approximate # of times program can call malloc to allocate
a single integer = 15268
Approximate # of times program can call malloc to allocate
a single integer = 14266
This program determines how much free space is available for
integers in the default data segment. Then it allocates
space for 1000 integers and checks the space again, using
_freect.
(printed 6/18/89)