How does the caching mechanism work in our Co.?



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

How does the caching mechanism work in our Co.?

Postby SurrenderX » Mon Apr 29, 2013 2:41 am

Hello

I've learned how to develop with COBOL in a big company (COBOL 85). It isn't real COBOL, because we have to use a framework for things like file or error handling. It simplifies many things, but I've never learned how to develop with real COBOL because of that. I noticed that we have in some of our programms a caching mechanism and I couldn't figure out how and why it works. The pattern is really simple: Check with a flag at the beginning of the programm if it is called the first time. If the flag is set to true, then do a SQL, store everything in the working-storage area and return the data. If the flag is set to false (=not the first call), return the data from the working-storage area. My colleagues could only tell me, that the memory stays allocated for a CICS transaction until the end. The memory allocation of the last call is used, if the same programm is called again and it is therefore important to initialize everything.

My question is why it uses the same memory allocation and why it doesn't deallocate the memory if it isn't used anymore. Is this normal in COBOL? I was shocked to hear that as former JAVA developer. I would expect atleast a new memory allocation for every call.

Example if it isn't clear: Programm A calls programm B. Progamm B calls programm D which executes a SQL and stores everything. Programm B is finished and Programm A calls now Programm C. Programm C needs the same information as Programm B and calls Programm D. Programm D knows that this is not the first call because of a flag and returns the stored data from the last call. Programm C finishes and Programm A also.

As you might have noticed, English isn't my first language. Please ask if something is unclear.

Cheers
SurrenderX
 
Posts: 2
Joined: Mon Apr 29, 2013 2:06 am
Has thanked: 6 times
Been thanked: 0 time

Re: How does the caching mechanism work in our Co.?

Postby dick scherrer » Mon Apr 29, 2013 4:17 am

Hello and welcome to the forum,

I suspect that "caching" is not really your question (Engilsh will improve over time<g>).

Most often "things" are re-used rather than go thru the overhead to re-allocate them.

At a quick look, i do not see anythng to cause concern. Possibly i misunderstand.
Hope this helps,
d.sch.

These users thanked the author dick scherrer for the post:
SurrenderX (Tue Apr 30, 2013 2:04 am)
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: How does the caching mechanism work in our Co.?

Postby Robert Sample » Mon Apr 29, 2013 4:58 am

COBOL considers the unit of work to start when the main program is invoked and to end when the main program ends (GOBACK or EXIT PROGRAM is executed). Memory is allocated for subprograms when they are called, and there is a CANCEL statement to free memory; otherwise the memory will not be freed as long as the main program executes. COBOL is not Java nor C -- COBOL has been around for over 50 years, and it has worked consistently the same way for that entire time.

These users thanked the author Robert Sample for the post:
SurrenderX (Tue Apr 30, 2013 2:04 am)
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: How does the caching mechanism work in our Co.?

Postby Ed Goodman » Mon Apr 29, 2013 8:47 pm

The theory is that it's more expensive to keep re-allocationg the memory and initializing the working storage than to have the program reset the memory it already has. I think this is called reusability, and maybe re-entrance. I'm sure there is a difference between those two, but as a developer, I just know to always assume that my memory needs cleaned up.

These users thanked the author Ed Goodman for the post:
SurrenderX (Tue Apr 30, 2013 2:04 am)
Ed Goodman
 
Posts: 341
Joined: Thu Feb 24, 2011 12:05 am
Has thanked: 3 times
Been thanked: 17 times

Re: How does the caching mechanism work in our Co.?

Postby dick scherrer » Mon Apr 29, 2013 10:22 pm

Hello,

The (overly simple) way i explain the difference between re-entrant and re-usable code is that re-entrant code can be used by multiple "users" at the same time. This code may not modify data within the code (i.e. working storage).

Re-usable code may have only one "user" at a time and should be reinitialized when a new process invokes the code.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: How does the caching mechanism work in our Co.?

Postby SurrenderX » Tue Apr 30, 2013 2:17 am

Thank you very much for the quick answer! I didn't expect this. :D

This solves the puzzle for me. Everything makes sense, if the memory stays allocated in an unit of work as long as it doesn't get de-allocated.
Is there a name for the described pattern? I was unsure of how it works, because I couldn't find any informations about it.

Cheers
SurrenderX
 
Posts: 2
Joined: Mon Apr 29, 2013 2:06 am
Has thanked: 6 times
Been thanked: 0 time

Re: How does the caching mechanism work in our Co.?

Postby dick scherrer » Tue Apr 30, 2013 7:35 pm

Hello,

You're welcome :)

Is there a name for the described pattern?
Not that i am aware of. I suspect there is, but . . .

When people are writing code, many are not aware that these considerations exist . . .
Hope this helps,
d.sch.

These users thanked the author dick scherrer for the post:
SurrenderX (Fri May 03, 2013 1:31 am)
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: How does the caching mechanism work in our Co.?

Postby Ed Goodman » Wed May 01, 2013 6:14 pm

It's called reusability if you want to research it.

These users thanked the author Ed Goodman for the post:
SurrenderX (Fri May 03, 2013 1:31 am)
Ed Goodman
 
Posts: 341
Joined: Thu Feb 24, 2011 12:05 am
Has thanked: 3 times
Been thanked: 17 times

Re: How does the caching mechanism work in our Co.?

Postby chaat » Thu May 02, 2013 4:29 am

if this process is executing in a CICS region, it may also be using GETMAIN SHARED to acquire storage (memory) which will remain in the region until it is explicitly freemain'd or the region comes down.

Chuck H.

These users thanked the author chaat for the post:
SurrenderX (Fri May 03, 2013 1:31 am)
chaat
 
Posts: 27
Joined: Sun Aug 16, 2009 11:07 pm
Location: St. Cloud, Minnesota
Has thanked: 0 time
Been thanked: 1 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post