MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Allocate new Node & Deallocate of a Cobol link list

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
SangNa
Beginner


Joined: 15 May 2003
Posts: 6
Topics: 4

PostPosted: Fri May 16, 2003 7:36 am    Post subject: Allocate new Node & Deallocate of a Cobol link list Reply with quote

Hi,
Is anyone got any example how to Allocate a new Node & Deallocate all Nodes of a link list in Cobol. I have include a brief paragraph from The Kasten COBOL Page, but I do not know how to call GETMAIN and FREEMAIN macros as described.

Thank you
Embarassed



Allocating memory in COBOL
Traditional COBOL does not allocate memory dynamically. Character strings and other objects generally have fixed lengths, hard-coded in WORKING-STORAGE.
Some dialects of COBOL, including COBOL 370, provide special facilities for allocating and deallocating memory. CICS has special commands for this purpose as well.

Most of JOCKEY was written in COBOL II, where no such facility is available. Instead, JOCKEY uses some Assembler routines, which are wrappers for GETMAIN and FREEMAIN macros. However, these routines incur a fair amount of overhead. They are also cumbersome to use because you must tell the FREEMAIN wrapper how many bytes to free.

In part for these reasons, JOCKEY encapsulates these routines in the JK011 module, which manages pools of variously-sized pieces of memory.

Allocating multiple pieces at a time
When maintaining data structures, you generally juggle multiple instances of the same kind of object. One way to allocate them is to declare an array of those objects in WORKING-STORAGE. Whenever you need another instance, increment a subscript that keeps track of the number allocated. Naturally you must make sure you don't exceed the array size.
The JK011 routines extend this approach by allocating arrays dynamically as needed. For each memory pool opened by a call to MCBOPEN, JK011 maintains a linked list of arrays. When you call MCBITEM to allocate an individual item, MCBITEM allocates it from the current array. If the current array is already exhausted, MCBITEM allocates another array and adds it to the list.

This approach is a compromise between efficiency and flexibility. With only a few expensive calls to GETMAIN and FREEMAIN, the application can get as much memory as it needs, without declaring a single huge array in WORKING-STORAGE that will be mostly unused.

Deallocation
How you deallocate something depends on how you allocate it. If you allocate objects one at a time through a facility such as malloc() or GETMAIN, you can probably deallocate it through a matching facility such as free() or FREEMAIN.
Likewise if you allocate multiple objects at a time, you can deallocate multiple objects at a time. If you allocate from a WORKING-STORAGE table, you can reset your subscript. If you allocate from a memory pool created by MCBOPEN, you can call MCBCLEAR or MCBFREE.
Back to top
View user's profile Send private message
mok
Beginner


Joined: 16 May 2003
Posts: 12
Topics: 0
Location: paris

PostPosted: Fri May 16, 2003 9:58 am    Post subject: Reply with quote

Hi SangNa,
You can use the CEEGTST (GeT STorgage) and CEEFRST (FRee STorage) callables services with Language Environment.
Here is a link to IBM publications :
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/ceea2120/3.3.6.5
Bye
Back to top
View user's profile Send private message
SangNa
Beginner


Joined: 15 May 2003
Posts: 6
Topics: 4

PostPosted: Sat May 17, 2003 6:54 am    Post subject: Reply with quote

Thank you for your information,

I'd like to be more specific of my problem, please help me on this

I am planning to use array of Pointer in Batch enviroment on MVS machine,

My working storage declare:
01 ws-linklist .
03 ws-linklist-array occurs 20 times .
05 ws-linklist-pointer usage pointer .
05 ws-tag-name pic x(03) .
05 ws-val-len pic 9(04) comp .
05 ws-val-text pic x(50) .

The problem that I have are :
1. How to allocate a new node (is there any command like "allocate ws-linklist-pointer ? "
ie. will MVS allocate the memory for me or I have to allocate using the following call from IBM
CALL "CEEGTST" USING HEAPID, STGSIZE,ADDRSS, FC.

then I will use the ADDRSS from the above call to establish address for my pointer ?
move ADDRSS to ws-linklist-pointer(1)

2. I am using array of pointer (20 elements of link-list). Do I have to allocate or establish the address for each link-list ?

Thanks
Back to top
View user's profile Send private message
mok
Beginner


Joined: 16 May 2003
Posts: 12
Topics: 0
Location: paris

PostPosted: Mon May 19, 2003 4:19 am    Post subject: Reply with quote

I think that you make a mistake in interpretation. When you submit a JOB, this one is carried out in an INIT. You should not call CEEGTST, except if the memory available in this INIT is insufficient; if not, the management of the memory is automatic.
In addition, such as you describe your problem, I am not sure that you need a pointer. From where do you receive these informations which you want to load in table ? If it is from an element of a file you are reading, the pointer is not essential. If it is from an element of linkage, you must also define a pointer in linkage section, in the following way:
linkage Section.
01 lnk-ptr.
05 lnk-pointer Pointer Occurs 20.
Then you will address your pointer like this:
Set ws-linklist-pointer(n) to lnk-pointer(n)

Cheers
Back to top
View user's profile Send private message
DaveyC
Moderator


Joined: 02 Dec 2002
Posts: 151
Topics: 3
Location: Perth, Western Australia

PostPosted: Tue May 20, 2003 4:23 am    Post subject: Reply with quote

Of course you will need to use a pointer if your trying to use linked lists! To get the storage you will need to use GEEGTST in batch or foreground. Avoid using GETMAIN/FREEMAIN at all costs...

Quote:

2. I am using array of pointer (20 elements of link-list). Do I have to allocate or establish the address for each link-list ?


I don't understand what you mean. 20 elements of a linked list? Or do you mean 20 linked-lists whose pointers are stored in an array?

Quote:

CALL "CEEGTST" USING HEAPID, STGSIZE,ADDRSS, FC.


You probably don't need HEAPID unless you are planning to use heap pools.
_________________
Dave Crayford
Back to top
View user's profile Send private message Send e-mail
Spolacek
Beginner


Joined: 17 Dec 2002
Posts: 17
Topics: 2
Location: NJ, USA

PostPosted: Fri May 23, 2003 10:40 am    Post subject: Reply with quote

IBM supplies a sample COBOL program to demonstrate how to use Language Environment services CEEGTST and CEEFRST. The sample program uses these services to build a linked list.

This sample program (and many other sample programs that demonstrate how to use LE services) is in the LE samplib. Please check your system for a library whose name is like the following:

SYS1.CEE.SCEESAMP

The member name for the linked list program is IGZTLLST. If you can't find the library under the above name, check with the systems programmers in your shop. They can tell you the name under which it resides on your system.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group