[Previous]
[Contents]
[Next]

_heapgrow(), _fheapgrow(), _nheapgrow()

increase the size of a heap

Synopsis:

#include <malloc.h>
void  _heapgrow( void );
void _nheapgrow( void );
void _fheapgrow( void );

Description:

The _nheapgrow() function attempts to grow the near heap to the maximum size of 64K. You will want to do this in the small data models if you are using both malloc() and _fmalloc() or halloc(). Once a call to _fmalloc() or halloc() has been made, you may not be able to allocate any memory with malloc() unless space has been reserved for the near heap using malloc(), sbrk() or _nheapgrow().

The _fheapgrow() function doesn't do anything to the heap because the far heap is extended automatically when needed. If the current far heap cannot be extended, then another far heap is started.

In a small data memory model, the _heapgrow() function is equivalent to _nheapgrow(); in a large data memory model, the _heapgrow() function is equivalent to the _fheapgrow() function.

Examples:

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

void main()
  {
    char *p, *fmt_string;
    fmt_string = "Amount of memory available is %u\n";
    printf( fmt_string, _memavl() );
    _nheapgrow();
    printf( fmt_string, _memavl() );
    p = (char *) malloc( 2000 );
    printf( fmt_string, _memavl() );
  }

produces the output:

Amount of memory available is 0
Amount of memory available is 62732
Amount of memory available is 60730

Classification:

WATCOM

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

_heapchk(), _heapenable(), _heapmin(), _heapset(), _heapshrink(), _heapwalk()


[Previous]
[Contents]
[Next]