Improve the performance of the RPG program – Tip2
Page 1 of 1
Improve the performance of the RPG program – Tip2
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)
/free
// 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;
/end-free
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)
/free
// 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;
/end-free
Similar topics
» Improve the performance of the RPG program - Tip1
» Lower level program error handled in Higher level program
» Name the Indicators - Tip2
» Improve performance of JDBC connectivity
» Debug a batch program
» Lower level program error handled in Higher level program
» Name the Indicators - Tip2
» Improve performance of JDBC connectivity
» Debug a batch program
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|