Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ free(DOS) — OpenDesktop Software Development System 1.0.0d

Media Vault

Software Library

Restoration Projects

Artifacts Sought

     Name
          free, _ffree, _nfree - Deallocate memory blocks.

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

          void free(buffer)
          void *buffer;

          void _ffree(buffer)
          void far *buffer;

          void _nfree(buffer)
          void near *buffer;

     Description
          The free family of functions deallocates a memory block. The
          argument buffer points to a memory block previously
          allocated through a call to calloc, malloc, or realloc. The
          number of bytes freed is the number of bytes specified when
          the block was allocated (or reallocated, in the case of
          realloc). After the call, the freed block is available for
          allocation.

          Attempting to free an invalid pointer may affect subsequent
          allocation and cause errors. An invalid pointer is one not
          allocated with the appropriate call. Only blocks allocated
          with calloc, malloc, or realloc can be freed with free, only
          blocks allocated with _fmalloc can be freed with _ffree, and
          only blocks allocated with _nmalloc can be freed with
          _nfree.

          A null pointer argument is ignored.

          In large data models (compact- and large-model programs),
          free maps to _ffree. In small data models (small- and
          medium-model programs), free maps to _nfree.

          The various free functions deallocate a memory block in the
               data segments shown in the following table:

               Function   Data Segment
               free       Depends on data model of program

               _ffree     Far heap (outside default data segment)

               _nfree     Near heap (inside default data segment)

          The argument buffer points to a memory block previously
          allocated through a call to the corresponding malloc
          functions. The number of bytes freed is the number of bytes
          specified when the block was allocated. After the call, the
          freed block is again available for allocation.

     Return Value
          None.

     See Also
          calloc(S), _fmalloc(DOS), malloc(DOS), _nmalloc(DOS),
          realloc(S)

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

          void *alloc;

          main()
           {
                  /* If there is nothing to free... */

                  if ((alloc = malloc(100)) == NULL)
                          printf("Unable to allocate memory\n");
                  else
                  {
                          /* Free memory for the heap: */
                          free(alloc);
                          printf("100 bytes freed\n");
                  }
           }

          This program uses malloc to allocate a block of memory and
          then uses free to free this block.

                                                (printed 6/18/89)



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026