IBM AS/400 manual Heap Storage Problems, Managing Dynamically-Allocated Storage

Models: AS/400

1 489
Download 489 pages 47.95 Kb
Page 142
Image 142
of 5). Memory Management - Build a Linked List of Names
Figure 52 (Part 5

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 poin￿ter 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

 

 

 

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 heap storage.

118 ILE RPG for AS/400 Programmer's Guide

Page 142
Image 142
IBM AS/400 manual Heap Storage Problems, Managing Dynamically-Allocated Storage