[Previous]
[Contents]
[Next]

free(), _bfree(), _ffree(), _nfree()

deallocate a block of memory

Synopsis:

#include <stdlib.h>  /* For ANSI compatibility 
                        (free only) */
#include <malloc.h>  /* Required for other function 
                        prototypes */
void free( void *ptr );
void _bfree( __segment seg,
             void __based(void) *ptr );
void _ffree( void __far  *ptr );
void _nfree( void __near *ptr );

Description:

When the value of the argument ptr is NULL, the free() function does nothing; otherwise, the free() function deallocates the memory block located by the argument ptr, which points to a memory block previously allocated through a call to the appropriate version of calloc(), malloc() or realloc(). After the call, the freed block is available for allocation.

Each function deallocates memory from a particular heap, as listed below:

free()
Depends on data model of the program (see below)
_bfree()
Based heap specified by seg value
_ffree()
Far heap (outside the default data segment)
_nfree()
Near heap (inside the default data segment)

Note: In a large data memory model, free() is equivalent to _ffree(); in a small data memory model, free() is equivalent to _nfree().

Examples:

#include <stdio.h>
#include <stdlib.h>

void main()
  {
    char *buffer;

    buffer = (char *)malloc( 80 );
    if( buffer == NULL ) {
      printf( "Unable to allocate memory\n" );
    } else {

      /* rest of code goes here */

      free( buffer );  /* deallocate buffer */
    }
  }

Classification:

free() is ANSI; _bfree(), _ffree(), and _nfree() are WATCOM.
Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

calloc(), _expand(), halloc(), hfree(), malloc(), _msize(), realloc(), sbrk()


[Previous]
[Contents]
[Next]