IBM AS/400 Frozen Dessert Maker User Manual


 
Managing Dynamically-Allocated Storage
*-----------------------------------------------------------------*
* S U B P R O C E D U R E S *
*-----------------------------------------------------------------*
*-----------------------------------------------------------------*
* AddName - add a name to the end of the list *
*-----------------------------------------------------------------*
P AddName B
D AddName pi
D name 40A
*-----------------------------------------------------------------*
* Allocate a new element for the array, pointed at by the *
* 'next' pointer of the current end of the list. *
* *
* Before: *
* *
* .-------------. *
*| | *
* | name *--->abc *
* | name_len 3 | *
* | next *-------||| *
*| | *
* '-------------' *
* *
*-----------------------------------------------------------------*
C ALLOC elemSize next@
*-----------------------------------------------------------------*
* *
* After: Note that the old element is still the current one *
* because elem@ is still pointing to the old element *
* *
* .-------------. .--------------. *
* | | .------>| | *
* | name *--->abc | | | *
* | name_len 3 | | | | *
* | next *----------' | | *
*| | | | *
* '-------------' '--------------' *
* *
* Now set elem@ to point to the new element *
*-----------------------------------------------------------------*
C EVAL elem@ = next@
Figure 52 (Part 2 of 5). Memory Management - Build a Linked List of Names
Chapter 9. Running a Program 115