IBM AS/400 Frozen Dessert Maker User Manual


 
Managing Dynamically-Allocated Storage
For more information on the RCLRSC command, refer to the
CL Reference
(Abridged)
. For more information on the RCLRSC and activation groups, refer to
ILE Concepts
.
Managing Dynamically-Allocated Storage
ILE allows you to directly manage run-time storage from your program by managing
heaps. A heap is an area of storage used for allocations of dynamic storage. The
amount of dynamic storage required by an application depends on the data being
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, you may want
to do so if you want to make use of dynamically allocated run-time storage. For
example, you may want to do this if you do not know exactly how large an array or
multiple-occurrence data structure should be. You could define the array or data
structure as BASED, and acquire the actual storage for the array or data structure
once your program determines how large it should be.
There are two types of heaps available on the system: a default heap and a user-
created heap. The RPG storage management operations use the default heap. The
following sections show how to use RPG storage management operations with the
default heap, and also how to create and use your own heap using the storage
management APIs. For more information on user-created heaps and other ILE
storage management concepts refer to
ILE Concepts
.
Managing the Default Heap Using RPG Operations
The first request for dynamic storage within an activation group results in the cre-
ation of a default heap from which the storage allocation takes place. Additional
requests for dynamic storage are met by further allocations from the default heap. If
there is insufficient storage in the heap to satisfy the current request for dynamic
storage, the heap is extended and the additional storage is allocated.
Allocated dynamic storage remains allocated until it is explicitly freed or until the
heap is discarded. The default heap is discarded only when the owning activation
group ends.
Programs in the same activation group all use the same default heap. If one
program accesses storage beyond what has be allocated, it can cause problems for
another program. For example, assume that two programs, PGM A and PGM B are
running in the same activation group. 10 bytes are allocated for PGM A, but 11
bytes are changed by PGM A. If the extra byte was in fact allocated for PGM B,
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 from
any heap.
The REALLOC operation changes the size of previously allocated storage from
any heap.
Chapter 9. Running a Program 113