Stack and Heap concept in COBOL 
Author Message
 Stack and Heap concept in COBOL

Hi,  
  I am new to this group.I am a bit confused about the memory
allocation in COBOL. Till now i was under the impression that there is
no dynamic allocation of memory in COBOL and the Working storage
variables are allocated memory when the load module is loaded.
  But i found the following information about Working storage
variables in an IBM manual:
Usage of Stack and Heap Storage by Language Environment-Conforming
Languages

Language  Stack                       Heap  
COBOL    Intrinsic functions          WORKING-STORAGE variables      
         Library routines                                            
         LOCAL-STORAGE variables(1)                                  

 STACK        Used by library routine stack frames that can reside
                 anywhere in storage
 HEAP         Allocates storage for user-controlled dynamically
                 allocated variables  

  Could anyone help me with understanding this?

Thanks in advance,
Shyam Menon.



Sat, 10 Jul 2004 14:57:35 GMT  
 Stack and Heap concept in COBOL
Shyam Menon writes ...

Quote:
>Hi,  
>  I am new to this group.I am a bit confused about the memory
>allocation in COBOL. Till now i was under the impression that there is
>no dynamic allocation of memory in COBOL and the Working storage
>variables are allocated memory when the load module is loaded.
>  But i found the following information about Working storage
>variables in an IBM manual:
>Usage of Stack and Heap Storage by Language Environment-Conforming
>Languages

>Language  Stack                       Heap  
>COBOL    Intrinsic functions          WORKING-STORAGE variables      
>         Library routines                                            
>         LOCAL-STORAGE variables(1)                                  

> STACK        Used by library routine stack frames that can reside
>                 anywhere in storage
> HEAP         Allocates storage for user-controlled dynamically
>                 allocated variables  

>  Could anyone help me with understanding this?

There is no _explicit_ dynamic allocation of memory in COBOL '85, even with the
'89 amendment. There may be some in COBOL 2002, but I haven't looked at the new
proposed standard yet.

But the IBM mainframe COBOL compiler uses dynamic allocation behind the scenes
as you described. In addition, all supported IBM compilers now require the use
of a facility called "Language Environment" (LE). LE includes callable
functions to dynamically allocate, resize, and free Heap storage.

Hope this helps.

Kind regards,

Steve Comstock
Telephone: 303-393-8716
www.trainersfriend.com

256-B S. Monaco Parkway
Denver, CO 80224
USA



Sat, 10 Jul 2004 20:57:24 GMT  
 Stack and Heap concept in COBOL

Quote:

> Hi,  
>   I am new to this group.

Well, hello and welcome to CLC!

Quote:
> I am a bit confused about the memory allocation in COBOL.

Don't mind, others are confused, too &-))

Quote:
> Till now i was under the impression that there is
> no dynamic allocation of memory in COBOL and the Working storage
> variables are allocated memory when the load module is loaded.

Yes, you are right. WORKING-STORAGE is allocated when the program is
executed for the first time in a thread and remains allocated (and in
its last used state) if you call the program again. So , variables in
WORKING-STORAGE behave like they where static variables of a C or PL/I
program.

Quote:
>   But i found the following information about Working storage
> variables in an IBM manual:
> Usage of Stack and Heap Storage by Language Environment-Conforming
> Languages

> Language  Stack                       Heap  
> COBOL    Intrinsic functions          WORKING-STORAGE variables      
>          Library routines                                            
>          LOCAL-STORAGE variables(1)

OK, now we are talking of LOCAL-STORAGE instead of WORKING-STORAGE.
Variables which are declared in the LOCAL-STORAGE Section are
allocated in the STACK rather than in the HEAP. They are intialized at
every entry of the program and freed as soon as the program reaches
its end.
You will not be too surprised if I tell you that this kind of
variables is called automatic in C and PL/I. You need LOCAL-STORAGE
variables if you need a COBOL program to be called recursive (and of
course you need at least one variable in WORKING-STORAGE to be able to
stop the recursion).

OK, and the library routines and the intrinsic functions use the STACK
too. Probably, these routines are written in C and use automatic
storage. No problem, let them use what they have to use!

Quote:

>  STACK        Used by library routine stack frames that can reside
>                  anywhere in storage

I'd guess you are now in another chapter of the manual. In which
chapter?

Quote:
>  HEAP         Allocates storage for user-controlled dynamically
>                  allocated variables

If a user-program ALLOCATEs storage, it gets HEAP storage. In COBOL,
there is no verb for ALLOCATE, you have to CALL CEEGTST.

Quote:

>   Could anyone help me with understanding this?

OK, now exactly WHAT are you trying to understand? If you are aware of
the (writable) static and the automatic concept in C, you should be
happy to see that COBOL is able to handle these kind of storage too.
But, to be honest, most people know that in COBOL all variables are in
its last used state, so they forget about the VALUE clause and they
are just happy.

Quote:

> Thanks in advance,
> Shyam Menon.

Daniel


Sat, 10 Jul 2004 22:15:50 GMT  
 Stack and Heap concept in COBOL
FYI-
  The (opposed/draft) 2002 Standard *does* introduce the ALLOCATE and FREE
statements for "explicit" dynamic storage allocation.

It also distinguishes Working-Storage from Local-Storage.  In *most*
implementations (although this is NOT specified in the draft Standard), I
would expect Local-Storage to be allocated from "stack storage".  IBM (along
with Micro Focus - and possibly some others) already supports Local-Storage
as an EXTENSION to the '85/'89/'91 Standard.
--
Bill Klein
 wmklein <at> ix.netcom.com

Quote:
> Shyam Menon writes ...

 <snip>

> There is no _explicit_ dynamic allocation of memory in COBOL '85, even
with the
> '89 amendment. There may be some in COBOL 2002, but I haven't looked at
the new
> proposed standard yet.



Sun, 11 Jul 2004 09:01:01 GMT  
 Stack and Heap concept in COBOL
Talk about a "typo"  <G> (aka Freudian slip)

That "(opposed/draft) 2002 Standard" was SUPPOSED to be "proposed/draft"

--
Bill Klein
 wmklein <at> ix.netcom.com


Quote:
> FYI-
>   The (opposed/draft) 2002 Standard *does* introduce the ALLOCATE and FREE
> statements for "explicit" dynamic storage allocation.

> It also distinguishes Working-Storage from Local-Storage.  In *most*
> implementations (although this is NOT specified in the draft Standard), I
> would expect Local-Storage to be allocated from "stack storage".  IBM
(along
> with Micro Focus - and possibly some others) already supports
Local-Storage
> as an EXTENSION to the '85/'89/'91 Standard.
> --
> Bill Klein
>  wmklein <at> ix.netcom.com


> > Shyam Menon writes ...

>  <snip>

> > There is no _explicit_ dynamic allocation of memory in COBOL '85, even
> with the
> > '89 amendment. There may be some in COBOL 2002, but I haven't looked at
> the new
> > proposed standard yet.



Sun, 11 Jul 2004 10:03:01 GMT  
 Stack and Heap concept in COBOL
Hi,
                Referring to your reply "WORKING-STORAGE is allocated
when the program is executed for the first time in a thread and
remains allocated (and in its last used state)".
                Now my concern  is if WORKING-STORAGE is defined at
run time then at compile time why I have to compile with REGION = 0M
When length of data defined in WORKING-STORAGE is too high?
               when I tried with REGION=6M I got MAXCC=16?These two
are contradicting each other.
              Please clear my doubts.
Thanks and Regards.
shyam
*******************************************************************************
Quote:


> > Hi,  
> >   I am new to this group.

> Well, hello and welcome to CLC!

> > I am a bit confused about the memory allocation in COBOL.

> Don't mind, others are confused, too &-))

> > Till now i was under the impression that there is
> > no dynamic allocation of memory in COBOL and the Working storage
> > variables are allocated memory when the load module is loaded.

> Yes, you are right. WORKING-STORAGE is allocated when the program is
> executed for the first time in a thread and remains allocated (and in
> its last used state) if you call the program again. So , variables in
> WORKING-STORAGE behave like they where static variables of a C or PL/I
> program.

> >   But i found the following information about Working storage
> > variables in an IBM manual:
> > Usage of Stack and Heap Storage by Language Environment-Conforming
> > Languages

> > Language  Stack                       Heap  
> > COBOL    Intrinsic functions          WORKING-STORAGE variables      
> >          Library routines                                            
> >          LOCAL-STORAGE variables(1)

> OK, now we are talking of LOCAL-STORAGE instead of WORKING-STORAGE.
> Variables which are declared in the LOCAL-STORAGE Section are
> allocated in the STACK rather than in the HEAP. They are intialized at
> every entry of the program and freed as soon as the program reaches
> its end.
> You will not be too surprised if I tell you that this kind of
> variables is called automatic in C and PL/I. You need LOCAL-STORAGE
> variables if you need a COBOL program to be called recursive (and of
> course you need at least one variable in WORKING-STORAGE to be able to
> stop the recursion).

> OK, and the library routines and the intrinsic functions use the STACK
> too. Probably, these routines are written in C and use automatic
> storage. No problem, let them use what they have to use!

> >  STACK        Used by library routine stack frames that can reside
> >                  anywhere in storage

> I'd guess you are now in another chapter of the manual. In which
> chapter?

> >  HEAP         Allocates storage for user-controlled dynamically
> >                  allocated variables

> If a user-program ALLOCATEs storage, it gets HEAP storage. In COBOL,
> there is no verb for ALLOCATE, you have to CALL CEEGTST.

> >   Could anyone help me with understanding this?

> OK, now exactly WHAT are you trying to understand? If you are aware of
> the (writable) static and the automatic concept in C, you should be
> happy to see that COBOL is able to handle these kind of storage too.
> But, to be honest, most people know that in COBOL all variables are in
> its last used state, so they forget about the VALUE clause and they
> are just happy.

> > Thanks in advance,
> > Shyam Menon.

> Daniel



Tue, 13 Jul 2004 11:59:08 GMT  
 Stack and Heap concept in COBOL
The amount of storage needed to compile a program has (close to) NOTHING to
do with the amount of storage allocated at run-time.  As you are using an
IBM mainframe compiler, check out your value for the SIZE *compiler-option".

For a RENT compiled program, the size of the load module *will* include the
size of all literals (both user-defined and compiler-defined) as well as (at
least one copy) of WS.  The amount of "virtual storage" needed to COMPILE a
program has LOTS to do with the "complexity" of the program, its source code
length, and many, MANY other items - with the size of WS being a "miniscule"
part of the equation.  The amount of virtual storage needed to RUN a COBOL
program (RENT, NORENT, with dynamic or static calls, whatever) *does* have a
lot to do with WS (and file section, and procedure division) and many, MANY
other things - most of which can be INFERRED from the load module size.

Shyam,
  I hate to keep coming back to this, but it really, REALLY sounds to me as
if you are approaching IBM mainframe COBOL development with

 A) inadequate training
 B) "misconceptions" based on different programming languages and operating
systems

--
Bill Klein
 wmklein <at> ix.netcom.com

Quote:
> Hi,
>                 Referring to your reply "WORKING-STORAGE is allocated
> when the program is executed for the first time in a thread and
> remains allocated (and in its last used state)".
>                 Now my concern  is if WORKING-STORAGE is defined at
> run time then at compile time why I have to compile with REGION = 0M
> When length of data defined in WORKING-STORAGE is too high?
>                when I tried with REGION=6M I got MAXCC=16?These two
> are contradicting each other.
>               Please clear my doubts.
> Thanks and Regards.
> shyam

****************************************************************************
***


Quote:
> > > Hi,
> > >   I am new to this group.

> > Well, hello and welcome to CLC!

> > > I am a bit confused about the memory allocation in COBOL.

> > Don't mind, others are confused, too &-))

> > > Till now i was under the impression that there is
> > > no dynamic allocation of memory in COBOL and the Working storage
> > > variables are allocated memory when the load module is loaded.

> > Yes, you are right. WORKING-STORAGE is allocated when the program is
> > executed for the first time in a thread and remains allocated (and in
> > its last used state) if you call the program again. So , variables in
> > WORKING-STORAGE behave like they where static variables of a C or PL/I
> > program.

> > >   But i found the following information about Working storage
> > > variables in an IBM manual:
> > > Usage of Stack and Heap Storage by Language Environment-Conforming
> > > Languages

> > > Language  Stack                       Heap
> > > COBOL    Intrinsic functions          WORKING-STORAGE variables
> > >          Library routines
> > >          LOCAL-STORAGE variables(1)

> > OK, now we are talking of LOCAL-STORAGE instead of WORKING-STORAGE.
> > Variables which are declared in the LOCAL-STORAGE Section are
> > allocated in the STACK rather than in the HEAP. They are intialized at
> > every entry of the program and freed as soon as the program reaches
> > its end.
> > You will not be too surprised if I tell you that this kind of
> > variables is called automatic in C and PL/I. You need LOCAL-STORAGE
> > variables if you need a COBOL program to be called recursive (and of
> > course you need at least one variable in WORKING-STORAGE to be able to
> > stop the recursion).

> > OK, and the library routines and the intrinsic functions use the STACK
> > too. Probably, these routines are written in C and use automatic
> > storage. No problem, let them use what they have to use!

> > >  STACK        Used by library routine stack frames that can reside
> > >                  anywhere in storage

> > I'd guess you are now in another chapter of the manual. In which
> > chapter?

> > >  HEAP         Allocates storage for user-controlled dynamically
> > >                  allocated variables

> > If a user-program ALLOCATEs storage, it gets HEAP storage. In COBOL,
> > there is no verb for ALLOCATE, you have to CALL CEEGTST.

> > >   Could anyone help me with understanding this?

> > OK, now exactly WHAT are you trying to understand? If you are aware of
> > the (writable) static and the automatic concept in C, you should be
> > happy to see that COBOL is able to handle these kind of storage too.
> > But, to be honest, most people know that in COBOL all variables are in
> > its last used state, so they forget about the VALUE clause and they
> > are just happy.

> > > Thanks in advance,
> > > Shyam Menon.

> > Daniel



Tue, 13 Jul 2004 13:19:53 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Heaps and Stacks question

2. Heap or Stack?

3. Schemes that allow *large* heap/stack?

4. Stack/heap continuation allocation, update 2

5. Stack/heap continuation allocation: an update

6. stack/heap continuation allocation

7. stack/heap continuation allocation

8. Heap or Stack?

9. stack and heap

10. Fortran memory allocation (stack/heap) issues

11. F90 allocated memory STACK or HEAP ??

12. Where do I learn about stacks/heaps/etc.?

 

 
Powered by phpBB® Forum Software