Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - free() release allocated dynamic memory http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 free()              Release allocated dynamic memory
------------------------------------------------------------------------------
 Declaration
   memory.hdr

 Syntax
   proc free extern
   param value _POINTER pAddress

 Arguments
   pAddress is a pointer to an allocated memory block.

 Return
   None.

 Description
   The free() procedure releases memory which was previously allocated by
   the calloc() or malloc() functions. Make sure to call free() with
   a valid memory pointer, i.e. that this pointer was retrieved from a
   call to calloc() or malloc(), otherwise the program will terminate with
   a runtime error.

 Example
   #define EXAMPLE_MEMORY
   #include example.hdr

   proc Test_free
   vardef
      ptr( byte ) pMem[ 11 ]
      uint        n
   enddef
   ? 0, coreleft()
   for n := 1 to 10
      pMem[ n ] := malloc( 1024 )      // allocate memory
      ? n, coreleft()                  // display amount of free memory
   next
   ?
   ? 10, coreleft()
   for n := 10 downto 1  // allocations must be released in reverse order
      free( pMem[ n ] )                // free memory
      ? n - 1, coreleft()              // display amount of free memory
   next
   endproc

   proc main
   Test_free()
   endproc

See Also: calloc() malloc()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson