IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Difference between satic and controlled storage clss in PL1


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
umamageswari

New User


Joined: 26 Apr 2005
Posts: 1

PostPosted: Tue Apr 26, 2005 12:31 pm
Reply with quote

Hi,
could any1 help me in bringing the Difference between satic and controlled storage clss in PL1.
Many thanks
Back to top
View user's profile Send private message
NitinD

New User


Joined: 03 May 2005
Posts: 3

PostPosted: Thu May 05, 2005 4:20 pm
Reply with quote

Static Storage
Variables declared with the STATIC attribute are allocated prior to running a program. They remain allocated until the program terminates.


In the following example, the variable X is allocated for the life of the program, but it can be referenced only within procedure B or any block contained in B. The variable Y gets the STATIC attribute and is also allocated for the life of the program.

dcl Y char(1?);
A: proc options(main);
B: proc;
declare X static internal;
end B;
end A;
C: proc;
Y = 'hello';
end C;

Controlled storage
Variables declared as CONTROLLED are allocated only when you specify them in an ALLOCATE statement. A controlled variable remains allocated until a FREE statement that names the variable is encountered or until the end of the program.
Controlled variables are partially independent of the program block structure, but not completely. The scope of a controlled variable can be internal or external.
When it is declared as internal, the scope of the variable is the block in which the variable is declared and any contained blocks. Any reference to a controlled variable that is not allocated is in error.


In the following example, the variable X can be validly referred to within procedure B
and that part of procedure A that follows execution of the CALL statement.

A: proc;
dcl X controlled;
call B;
...
B: proc;
allocate X;
...
end B;
end A;
Generally, controlled variables are useful when a program requires large data aggregates with adjustable extents.
Back to top
View user's profile Send private message
j_prameela2000

New User


Joined: 01 Jun 2005
Posts: 28
Location: Chennai

PostPosted: Fri Jun 17, 2005 10:14 am
Reply with quote

Static Storage:
Whenever the value of a variable must be saved between different invocations of the same procedure, storage for that variable has to be allocated statically. The storage is allocated before execution of the program and remains allocated throughout the entire execution of the program. Static variables are initialized only once - before execution of a program begins. They are established with their respective values at a compile time.
Eg :

DCL 1 STRUCTURE STATIC,
2 A FIXED DECIMAL(5,2),
2 B FIXED DECIMAL(5,2);
DCL TABLE(100) CHAR(10) STATIC;

Controlled Storage :
It is used to create a stack. The storage of controlled variables is allocated in the program by the ALLOCATE statement and released by the FREE statement.
Eg.
DCL A(100) FIXED DECIMAL(5) CONTROLLED;
ALLOCATE A;
GET LIST(A);
TOTAL = SUM(A);
FREE A;
A variable that has the CONTROLLED attribute is allocated upon the execution of an ALLOCATE statement specifying that identifier name. This allocation remains in effect even after the termination of the block in which it is allocated. Storage remains allocated until the execution of a FREE statement in which the identifier name is specified. The ALLOCATE statement may also be used to specify the amount of storage required for arrays if the array size is to be established during program execution rather than at compile time.
Eg :
DCL ARRAY(*,*) FIXED DECIMAL(5) CONTROLLED;
GET LIST(I,J);
ALLOCATE ARRAY(I,J);
Here * is used to indicate number of dimensions.
Back to top
View user's profile Send private message
sudheer648

New User


Joined: 23 May 2005
Posts: 97
Location: Chennai

PostPosted: Fri Jun 17, 2005 3:26 pm
Reply with quote

Hi Pramella,

1.If there is no associate Free Statement for an Allocate Statement in the Program the memory allocated will be freed after the end of the program or not

2.Because language doesnt any gargabe collector to remove all the dangling memory pointers.
Back to top
View user's profile Send private message
j_prameela2000

New User


Joined: 01 Jun 2005
Posts: 28
Location: Chennai

PostPosted: Fri Jun 17, 2005 4:10 pm
Reply with quote

Hi sudheer,

At the end of a program the allocated memory will get released. Consider an example :
I allocate x;
-
-
II allocate x;
-
-
If you want to access the firstly allocated x variable in the middle of the program unless and otherwise you release the memory storage of the secondly allocated x variable you cannot use the firstly allocated x variable since it is a stack (last in first out). Correct me if i am wrong.

Regards.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Difference between joblib and steplib JCL & VSAM 2
No new posts Pull data using date difference betwe... DB2 6
No new posts Difference between PLT txn and schedu... CICS 3
No new posts CLIST - Virtual storage allocation error CLIST & REXX 5
No new posts CICS vs LE: STORAGE option CICS 0
Search our Forums:

Back to Top