IBM AS/400 manual Managing Dynamically-Allocated Storage, Running a Program115, next@

Models: AS/400

1 489
Download 489 pages 47.95 Kb
Page 139
Image 139

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 Program115

Page 139
Image 139
IBM AS/400 manual Managing Dynamically-Allocated Storage, Running a Program115, next@