If the order of the declares is such that the size of a variable does not depend on the size of variables declared after it, then a dynamic allocation would not occur (so, for example, if c1 came after c2 in the first example, there would be no dynamic allocation. But as you note, even in some cases where the declares are not in that order, there will be no dynamic allocation. For example, in your second example, the size of c4 doesn't depend on anything before it, and so c3's size is easily figured out. There is some code in the compiler that attempts to reorder declares and effectively moves the declare for c3 after c4. But in the c1/c2 example, things appear a little complicated and no reordering is done.
But it would be best to declare them (when at all possible) so that dependent declares come after the declare on which they are dependent.
------------------------------
Peter Douxmont
------------------------------
Original Message:
Sent: Sun September 15, 2024 09:52 AM
From: Dave Rivers
Subject: declaration order and program performance
If we consider the question of direct allocation of data in the DSA vs. dynamic allocation, then it seems declaration order matters in some unclear fashion.
Consider this example set of declarations
dcl c1 char(2*size(c2));
dcl len fixed bin(31) value(20);
dcl c2 char(len);
The size of c1 isn't known at the declaration - so c1 is dynamically allocated. But - why isn't it known?
In this similar example:
dcl c3 char(2*size(c4));
dcl c4 float bin(70);
the size of c3 is known and it is not dynamically allocated.
Just wondering why it is the case that the first situation requires dynamic allocation when the second doesn't, and if there is some explanation in the documentation?
- Thanks -
- Dave R. -
------------------------------
Dave Rivers
------------------------------