[Previous]
[Contents]
[Next]

_heapshrink(), _bheapshrink(), _fheapshrink(), _nheapshrink()

shrink a heap to its smallest possible size

Synopsis:

#include <malloc.h>
int  _heapshrink( void );
int _bheapshrink( __segment seg );
int _fheapshrink( void );
int _nheapshrink( void );

Description:

The _heapshrink() functions attempt to shrink the heap to its smallest possible size by returning all free entries at the end of the heap back to the system. This can be used to free up as much memory as possible before using the system() function or one of the spawn() functions.

The various _heapshrink() functions shrink the following heaps:

_heapshrink()
Depends on data model of the program (see below)
_bheapshrink()
Based heap specified by seg value; _NULLSEG specifies all based heaps
_fheapshrink ()
Far heap (outside the default data segment)
_nheapshrink ()
Near heap (inside the default data segment)

In a small data memory model, _heapshrink() is equivalent to _nheapshrink(); in a large data memory model, _heapshrink() is equivalent to _fheapshrink(). It's identical to _heapmin().

Returns:

Zero if successful, and nonzero if some error occurred.

Examples:

#include <stdlib.h>
#include <malloc.h>

void main()
  {
    _heapshrink();
    system( "cd /home/fred" );
  }

Classification:

WATCOM

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

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


[Previous]
[Contents]
[Next]