Returns the amount of memory available for memory allocation.
#include <malloc.h> | Required only for function declarations |
unsigned int _freect( size_t size );
size | Item size in bytes |
The _freect function tells you how much memory is available for dynamic memory allocation in the near heap. It does so by returning the approximate number of times your program can call _nmalloc (or malloc in small data models) to allocate an item size bytes long in the near heap (default data segment).
The _freect function returns the number of calls as an unsigned integer.
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:None
calloc functions, _expand functions, malloc functions, _memavl, _msize functions, realloc functions
/* FREECT.C: This program determines how much free space is available for
* integers in the default data segment. Then it allocates space for
* 1,000 integers and checks the space again, using _freect.
*/
#include <malloc.h>
#include <stdio.h>
void main( void )
{
int i;
/* First report on the free space: */
printf( “Integers (approximate) available on heap: %u\n\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( “After allocating space for 1000 integers:\n” );
printf( “Integers (approximate) available on heap: %u\n\n”,
_freect( sizeof( int ) ) );
}
Integers (approximate) available on heap: 15212
After allocating space for 1000 integers:
Integers (approximate) available on heap: 14084