Builtin Function to get total size of a dynamic array?



IBM's cross-platform compiler PL/I for MVS, VM & VSE, OS/390 and Enterprise PL/I for z/OS

Builtin Function to get total size of a dynamic array?

Postby sathyanandak » Fri May 29, 2015 2:28 pm

Hello Forum,

I was try to find if any builtin function to get current size of all elements in total of a dynamic array allocated using controlled storage class. I am searching for builtin function to reduce LOC!
sathyanandak
 
Posts: 2
Joined: Tue May 27, 2014 7:37 pm
Has thanked: 1 time
Been thanked: 0 time

Re: Builtin Function to get total size of a dynamic array?

Postby enrico-sorichetti » Fri May 29, 2015 3:26 pm

You will find no such function ...

when You code something like
 ****** ***************************** Top of Data ******************************
 000001  Alloc:                                                                 
 000002      Proc Options(Main);                                               
 000003      dcl pliretc builtin;                                               
 000004      dcl 1 arr(*)  ctl,                                                 
 000005          5 num fixed bin(31) ;                                         
 000006      dcl dim fixed bin(31) init(200);                                   
 000007      allocate arr(dim);                                                 
 000008      call pliretc(0) ;                                                 
 000009      End;                                                               
 ****** **************************** Bottom of Data ****************************


once pl1 has allocated the <array>
to keep track of the max indexes values is up to You

I am searching for builtin function to reduce LOC!


if LOC as in common jargon means Lines Of Code
how will the knowledge of the % used for controlled things
reduce the LOC ???
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort

These users thanked the author enrico-sorichetti for the post:
sathyanandak (Fri Jul 17, 2015 12:06 pm)
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Builtin Function to get total size of a dynamic array?

Postby BillyBoyo » Fri May 29, 2015 3:42 pm

Because, enrico, function domagic() can hide literally several lines of code. Thus reducing the overall LOC. domagic() uses lots more CPU, but the bean-counters are concerned about LOC :-)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Builtin Function to get total size of a dynamic array?

Postby enrico-sorichetti » Fri May 29, 2015 4:20 pm

as usual it a problem of the carrot and the stick ...
a high LOC will show a high productivity
but the same will make the maintenance budget forecast larger
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Builtin Function to get total size of a dynamic array?

Postby prino » Sat May 30, 2015 3:57 am

sathyanandak wrote:I was try to find if any builtin function to get current size of all elements in total of a dynamic array allocated using controlled storage class. I am searching for builtin function to reduce LOC!

enrico-sorichetti wrote:You will find no such function ...

{snip}

once pl1 has allocated the <array>
to keep track of the max indexes values is up to You

CSTG (aka CURRENTSTORAGE, or as it's now called, CURRENTSIZE) will tell you, and if you

dcl array(i:j) fixed bin (31) ctl;
dcl (i,j) fixed bin (31);

i = 42;
j = 53:

alloc array;


the LBOUND, HBOUND and DIM builtins will all return the correct values. PL/I internally keeps track of every bound, dimension, length, etc of controlled variables, the programmer just uses the required builtins to find them!
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy
User avatar
prino
 
Posts: 635
Joined: Wed Mar 11, 2009 12:22 am
Location: Vilnius, Lithuania
Has thanked: 3 times
Been thanked: 28 times

Re: Builtin Function to get total size of a dynamic array?

Postby enrico-sorichetti » Sat May 30, 2015 10:56 am

Thanks Robert,

:oops: I read too quickly , misunderstood the question and misworded the reply ...

I had inferred that the TS wanted to know not how much was allocated but how much was used out of the allocated area
so I should have written ( for the original way I saw things )
to keep track of the max indexes values REACHED is up to You

instead of
to keep track of the max indexes values is up to You


anyway the comment about LOC is still valid

here is a snippet according to the revised understanding
( did not even have to write it, it was already there in my set of samples )

 ****** ***************************** Top of Data ******************************
 000001  Alloc:
 000002      Proc Options(Main);
 000003      dcl pliretc builtin;
 000004      dcl (i,j) fixed bin(31);
 000005      dcl a(i:j) fixed bin(31) ctl;
 000006      i=11; j=23;
 000007      allocate a;
 000008      put skip list(lbound(a,1));
 000009      put skip list(hbound(a,1));
 000010      put skip list(cstg(a));
 000011      put skip list(dim(a));
 000012      call pliretc(0) ;
 000013      End;
 ****** **************************** Bottom of Data ****************************


********************************* TOP OF DATA **********************************
            11
            23
            52
            13
******************************** BOTTOM OF DATA ********************************
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Builtin Function to get total size of a dynamic array?

Postby sathyanandak » Fri Jul 17, 2015 12:02 pm

Thanks Enrico :) I used your first approach using counter to then use length info and pointer to be passed to calling program for processing.
sathyanandak
 
Posts: 2
Joined: Tue May 27, 2014 7:37 pm
Has thanked: 1 time
Been thanked: 0 time


Return to PL/I

 


  • Related topics
    Replies
    Views
    Last post