return the number of bytes of memory available for allocation
#include <malloc.h> size_t _memavl( void );
The _memavl() function returns the number of bytes of memory available for dynamic memory allocation in the near heap (the default data segment). In the tiny, small and medium memory models, the default data segment is only extended as needed to satisfy requests for memory allocation. Therefore, you need to call _nheapgrow() in these memory models before calling _memavl() in order to get a meaningful result.
The number returned by _memavl() might not represent a single contiguous block of memory. Use the _memmax() function to find the largest contiguous block of memory that can be allocated. |
The number of bytes of memory available for dynamic memory allocation in the near heap (the default data segment).
#include <stdio.h> #include <malloc.h> void main() { char *p; char *fmt = "Memory available = %u\n"; printf( fmt, _memavl() ); _nheapgrow(); printf( fmt, _memavl() ); p = (char *) malloc( 2000 ); printf( fmt, _memavl() ); }
produces the output:
Memory available = 0 Memory available = 62732 Memory available = 60730
WATCOM
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | No |
calloc(), _freect(), _memmax(), _heapgrow(), malloc(), realloc()