IBM AS/400 Frozen Dessert Maker User Manual


 
Managing Dynamically-Allocated Storage
*-----------------------------------------------------------------*
* Free - release the storage used by the list *
*-----------------------------------------------------------------*
P Free B
D prv@ S *
*-----------------------------------------------------------------*
* Loop through the elements of the list until the next pointer is *
* *NULL, starting from the first real element in the list *
*-----------------------------------------------------------------*
C EVAL elem@ = %ADDR(first)
C EVAL elem@ = next@
C DOW elem@ <> *NULL
*-----------------------------------------------------------------*
* Free the storage for name *
*-----------------------------------------------------------------*
C DEALLOC name@
*-----------------------------------------------------------------*
* Save the pointer to current elem@
*-----------------------------------------------------------------*
C EVAL prv@ = elem@
*-----------------------------------------------------------------*
* Advance elem@ to the next element
*-----------------------------------------------------------------*
C EVAL elem@ = next@
*-----------------------------------------------------------------*
* Free the storage for the current element
*-----------------------------------------------------------------*
C DEALLOC prv@
C ENDDO
*-----------------------------------------------------------------*
* Ready for a new list:
*-----------------------------------------------------------------*
C EVAL elem@ = %ADDR(first)
P Free E
Figure 52 (Part 5 of 5). Memory Management - Build a Linked List of Names
Heap Storage Problems
Figure 53 on page 119 shows possible problems associated with the misuse of
heap storage.
118 ILE RPG for AS/400 Programmer's Guide