IBM AS/400 manual Managing the Default Heap Using RPG Operations, Managing Dynamically-Allocated

Models: AS/400

1 489
Download 489 pages 47.95 Kb
Page 137
Image 137

 

 

 

 

 

 

 

Managing

 

Dynamically-Allocated Storage

 

 

 

 

For

more

information

on the RCLRSC command, referCL

Referenceto the

 

 

 

(Abridged).

For

more

information

on

the

RCLRSC

and

activation

groups, refe

ILE

Concepts.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Managing Dynamically-Allocated

Storage

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ILE

allows

you

to

directly manage run-time

storage

from your

program

heaps. heapA

is

an

area

of

storage

used

for

allocations

of

dynamic

amount of dynamic storage required by an application depends on the

processed

by

the

programs

and

procedures

that

use the

heap.

You

manage

heaps

by using the storage management operations ALLOC,

REALLOC, and

DEALLOC

or by using

ILE

bindable

APIs.

 

 

 

 

You

are

not required to

explicitly

manage

run-time storage. However,

to do so if you

want to make use of dynamically allocated run-time

example, you may want to do

this

if

you

do not know exactly how la

multiple-occurrence data structure should be. You could define the a

structure

as

BASED,

and acquire the actual storage for the array o

once

your

program

determines

 

how

large

it

should

be.

 

 

 

There are two types of heaps available on the system: a default created heap. The RPG storage management operations use the default following sections show how to use RPG storage management operations wi default heap, and also how to create and use your own heap using management APIs. For more information on user-created heaps and other storage management concepts referILE Conceptsto .

Managing the Default Heap Using RPG Operations

The first request for dynamic storage within an activation group res

ation ofdefault heap from which the storage allocation takes place. Addi requests for dynamic storage are met by further allocations from th there is insufficient storage in the heap to satisfy the current storage, the heap is extended and the additional storage is alloca

Allocated dynamic storage remains allocated until it is explicitly free heap is discarded. The default heap is discarded only when the o group ends.

Programs in the same activation group all use the same default heap. program accesses storage beyond what has be allocated, it can caus another program. For example, assume that two programs, PGM A and PGM B running in the same activation group. 10 bytes are allocated for PGM bytes are changed by PGM A. If the extra byte was in fact alloc problems may arise for PGM B.

You can use the following RPG operations on the default heap:

¹

The

ALLOC

operation

allocates

storage within

the default heap.

¹

The

DEALLOC

operation

frees

one

previous

allocation of

heap storage

 

any

heap.

 

 

 

 

 

 

¹

The

REALLOC

operation

changes

the

size

of

previously

allocated stor

 

any

heap.

 

 

 

 

 

 

Chapter 9. Running a Program113

Page 137
Image 137
IBM AS/400 manual Managing the Default Heap Using RPG Operations, Managing Dynamically-Allocated, Storage