IBM AS/400 manual Managing Dynamically-Allocated Storage, Part, 1 of, DYNARRAY Subprocedures, 2 of

Models: AS/400

1 489
Download 489 pages 47.95 Kb
Page 147
Image 147
DYNARRAY Subprocedures

Managing Dynamically-Allocated Storage

*=================================================================

*DYNA_INIT: Initialize the array.

*Function: Create the heap and allocate an initial amount ￿of

*storage for the run time array. *=================================================================

P DYNA_INIT

B

EXPORT

*-----------------------------------------------------------------

 

* Local variables.

 

*-----------------------------------------------------------------

 

D Size

S

10I 0

*

 

 

*Start with a pre-determined number of elements.

C

Z-ADD

INITALLOC

NumElems

*

*Determine the number of bytes needed for the array.

C

EVAL

Size = NumElems * %SIZE(DynArr)

*

*Create the heap

C

CALLP

CEECRHP(HeapId : Size : 0 : 0 : *OMIT)

*

*Allocate the storage and set the array basing pointer

*to the pointer returned from the API.

 

*

 

 

 

* Note that the ALLOC operation code uses the default heap

￿so

 

* we must use the CEEGTST API to specify a different heap.

 

 

*

 

 

C

CALLP

CEEGTST(HeapId : Size : DynArr@ : *OMIT)

*

*Initialize the storage for the array.

C

1

DO

NumElems

I

5 0

C

 

CLEAR

 

DynArr(I)

 

C

 

ENDDO

 

 

 

P DYNA_INIT

E

 

 

 

 

 

 

 

 

Figure 56

(Part

1 of 5).

DYNARRAY Subprocedures

 

*=================================================================

*DYNA_TERM: Terminate array handling.

*Function: Delete the heap. *=================================================================

P DYNA_TERM

B

EXPORT

 

C

CALLP

CEEDSHP(HeapId

: *OMIT)

C

RESET

 

HeapVars

P DYNA_TERM

E

 

 

 

 

 

Figure 56 (Part

2 of 5).

DYNARRAY Subprocedures

Chapter 9. Running a Program123

Page 147
Image 147
IBM AS/400 manual Managing Dynamically-Allocated Storage, Part, 1 of, DYNARRAY Subprocedures, 2 of