[Previous]
[Contents]
[Next]

_memmax()

return the size of the largest contiguous block of memory available

Synopsis:

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

Description:

The _memmax() function returns the size of the largest contiguous block of memory available for dynamic memory allocation in the near heap (the default data segment).


Note: 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 _memmax() in order to get a meaningful result.

Returns:

The size of the largest contiguous block of memory available for dynamic memory allocation in the near heap. If this is 0, then there's no more memory available in the near heap.

Examples:

#include <stdio.h>
#include <malloc.h>

void main()
  {
    char *p;
    size_t size;

    size = _memmax();
    printf( "Maximum memory available is %u\n", size );
    _nheapgrow();
    size = _memmax();
    printf( "Maximum memory available is %u\n", size );
    p = (char *) _nmalloc( size );
    size = _memmax();
    printf( "Maximum memory available is %u\n", size );
  }

produces the output:

Maximum memory available is 0
Maximum memory available is 62700
Maximum memory available is 0

Classification:

WATCOM

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

calloc(), _freect(), _memavl(), _heapgrow(), malloc()


[Previous]
[Contents]
[Next]