PMS Information Systems
Welcome to PMS Information Systems - IBM i (AS/400) Forum !!!

Get Answers for all your queries on IBM i (AS/400).

Improve the performance of the RPG program – Tip2

Go down

Improve the performance of the RPG program – Tip2

Post  maran on Wed May 29, 2013 12:04 pm

Use ALLOC, REALLOC and DEALLOC opcodes to reduce Static Storage with Pointers to Arrays.

If we do not know how many items are going to be stored in the array usually we would declare the array with maximum DIM say 1000. So when program is called static storage is allocated to hold 32000 items. This can be overridden by the following way that we could allocate a small amount of storage initially say 100 and then increase the storage based on the user requirement.

To achieve this we use Memory management Opcodes ALLOC, REALLOC and DEALLOC opcodes.

D Array S 10 Dim(32000) Based(Ptr)
D Hundred_Item C 100
D Increment S 2 0 Inz (1)

// Allocate storage for 100 elements
Ptr = %alloc(Hundread_Item * %size(Array));

// Load 100 elements here

// Later, when more storage is needed

Increment += 1;

Ptr = %realloc(Ptr: Hundread_Item * Increment * %size(Array));

// Once you have done with Array then release the static storage

dealloc Ptr;


Posts : 442
Join date : 2009-07-24

View user profile

Back to top Go down

Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum