[Previous]
[Contents]
[Next]

_memavl()

return the number of bytes of memory available for allocation

Synopsis:

#include <malloc.h>
size_t _memavl( void );

Description:

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.


Note: 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.

Returns:

The number of bytes of memory available for dynamic memory allocation in the near heap (the default data segment).

Examples:

#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

Classification:

WATCOM

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

calloc(), _freect(), _memmax(), _heapgrow(), malloc(), realloc()


[Previous]
[Contents]
[Next]