Joined: 07 Apr 2010 Posts: 94 Location: Bangalore, India

Posted: Wed Feb 20, 2013 12:48 pm Post subject: Heap and Linked List

Hi All,

I am using IBM routines for creating a Heap dynamically and then getting the storage for linkage variable.

Using CEECRHP, I get the Heap ID.

Using CEEGTST, and passing the Heap ID retrieved in the above step, I get the storage based on the length of my Linkage variable.

Q1. Can anyone please suggest if I need to get the Heap ID for every node that I create in the Linked List or is it ok for me to get the Heap ID once and then Perform my loop 'n'-times for n number of nodes to get the storage within that Heap?

Also is there any way where I can display all the nodes of my linked list using a single display?

Does the internal storage look as below? or is my understanding incorrect?

Q2. Is is mandatory to use greater than or equal to 4096 in the HEAP-SIZE parameter of CEECRHP? Will it cause an error when my total size of all nodes is greater than size of the Heap?

Joined: 07 Apr 2010 Posts: 94 Location: Bangalore, India

Posted: Wed Feb 20, 2013 3:13 pm Post subject:

Hi PeterHolland,

I had and again have gone thru the topics you have pointed in the above post. I am still unable to get answers to those specific questions which I have raised.

I would be thankful if you could please provide more details and inputs from ur end.

Joined: 27 Oct 2009 Posts: 2463 Location: Netherlands, Amstelveen

Posted: Wed Feb 20, 2013 3:24 pm Post subject:

Quote:

Using CEECRHP, I get the Heap ID.

That is you want a new user heap.
Using HEAPID 0 gives you your standard heap.
In all calls to CEEGTST you supply the HEAPID.
So that will be the one obtained from CEECRHP or zero.
And if the total size of your nodes exceeds the heap size your
program will crash.
What more can I say?

Joined: 07 Apr 2010 Posts: 94 Location: Bangalore, India

Posted: Wed Feb 20, 2013 3:36 pm Post subject:

Thank you for your reply.

Quote:

And if the total size of your nodes exceeds the heap size your
program will crash.

This implies that my program should be aware of the size of one node * number of nodes required to store all the data. I believe this will static and not dynamic. Or else should I call the CEECRHP with the MAX possible HEAP-SIZE?

and
Is there any way where I can display all the nodes of my linked list using a single display?[/quote]

Posted: Wed Feb 20, 2013 3:36 pm Post subject: Reply to: Heap and Linked List

You are making things more complicated than they should be .
You are mixing two <relatively unrelated> concepts

1) <some> linked list where each node storage is acquired using CEEGTST

2) in which HEAP acquire the storage

The HEAP is used to <isolate> the <getmains> according to some logic, usually the homogeneity of the sizes requested

Your program <might> work acquiring storage from the common heap

so depending on the logic You might ....

1) acquire the storage for each node/list in the <main> heap
2) acquire the storage for each node/list in a new heap ( one heap for all lists )
3) allocate a heap for each list

if the application is allocating and dropping lists the 3 approach might be better
no need free each node storage to drop the list, just free the heap

Quote:

Also is there any way where I can display all the nodes of my linked list using a single display?

Posted: Wed Feb 20, 2013 3:41 pm Post subject: Reply to: Heap and Linked List

it is odd that somebody trying to use an advanced technique is not capable of reading and understanding the manuals itself

what is that You are not understanding here
( about the increment parameter ??? )

Quote:

z/OS: Language Environment Programming Reference
SA22-7562-09

CEECRHP lets you define additional heaps. It returns a unique heap_id. The heaps defined by CEECRHP can be used just like the initial heap (heap_id=0), below heap, and anywhere heap. Unlike the heaps created by these heap services, all heap elements within an additional heap can be quickly freed by a single call to CEEDSHP (discard heap).

The number of heaps supported by Language Environment is limited only by the amount of virtual storage available.

heap_id (output)
A fullword binary signed integer. heap_id is the heap identifier of the created heap. If a new heap cannot be created, the value of heap_id remains undefined.
Storage obtained from heap_ids 79 and 80 is set to binary 0 independent of any initialization value specified by the STORAGE option.

initial_size (input)
A fullword binary signed integer. initial_size is the initial amount of storage, in bytes, allocated for the new heap. initial_size is rounded up to the nearest increment of 4096 bytes.
If initial_size is specified as 0, then the init_size specified in the HEAP run-time option is used. If no HEAP run-time option was provided and initial_size is specified as 0, CEECRHP uses the installation default.

increment (input)
A fullword binary signed integer. When it is necessary to enlarge the heap to satisfy an allocation request, increment represents the number of bytes by which the heap is extended. increment is rounded up to the nearest 4096 bytes.
If increment is specified as 0, then the incr_size specified in the HEAP run time option is used. If no HEAP run-time option was provided and increment equals 0, CEECRHP uses the installation default.

options (input)
A fullword binary signed integer. options are specified with the decimal codes as shown in Table 24.
Table 24. HEAP Attributes Based on the Setting of the options Parameter
Option Setting HEAP Attributes
00 Use same attributes as the initial heap (copy them from the HEAP run-time option)
01 HEAP(,,,FREE) (location inherited from HEAP run-time option)
70 HEAP(,,,KEEP) (location inherited from HEAP run-time option)
71 HEAP(,,ANYWHERE,KEEP)
72 HEAP(,,ANYWHERE,FREE)
73 HEAP(,,BELOW,KEEP)
74 HEAP(,,BELOW,FREE)
75 HEAP(,,ANYWHERE,) (disposition inherited from the HEAP run-time option)
76 HEAP(,,BELOW,) (disposition inherited from the HEAP run-time option)
77 HEAP(,,ANYWHERE,KEEP) (all heap storage obtained using this heap_id is allocated on a 4K boundary)
78 HEAP(,,ANYWHERE,FREE) (all heap storage obtained using this heap_id is allocated on a 4K boundary)
79 HEAP(,,ANYWHERE,KEEP) (all heap storage obtained using this heap_id is set to binary 0 when allocated using CEEGTST)
80 HEAP(,,ANYWHERE,FREE) (all heap storage obtained using this heap_id is set to binary 0 when allocated using CEEGTST)
fc (output)
A 12-byte feedback code, optional in some languages, that indicates the result of this service.
The following Feedback Codes can result from this service:

Code Severity Message number Message text
CEE000 0 — The service completed successfully.
CEE0P2 4 0802 Heap storage control information was damaged.
CEE0P4 3 0804 The initial size value supplied in a create heap request was unsupported.
CEE0P5 3 0805 The increment size value supplied in a create heap request was unsupported.
CEE0P6 3 0806 The options value supplied in a create heap request was unrecognized.
CEE0PD 3 0813 Insufficient storage was available to satisfy a get storage request.

Posted: Wed Feb 20, 2013 3:48 pm Post subject: Reply to: Heap and Linked List

Quote:

Also is there any way where I can display all the nodes of my linked list using a single display?

not with the current Language Environment
IBM plans to implement a new cover function in place of all the existing functions

it will be called CEEPROPHET
it will do everything without being passed any parameter and ignoring the ones passed ( backwards compatibility )
, because it will know what the user wants without being told

Joined: 07 Apr 2010 Posts: 94 Location: Bangalore, India

Posted: Wed Feb 20, 2013 4:07 pm Post subject:

Thank you Enrico.

I had gone thru the same explanation before.

Quote:

And if the total size of your nodes exceeds the heap size your
program will crash.

According to what I understand the program will never abend, if I specify
Heap ID = 0
Initial size = 0
Increment = 0
Options = 0

and call CEECRHP. CEECRHP will use the installation default for initial size and for incrementing whenever required.

Quote:

so depending on the logic You might ....

1) acquire the storage for each node/list in the <main> heap
2) acquire the storage for each node/list in a new heap ( one heap for all lists )
3) allocate a heap for each list

I was planning to use the 2nd option but as suggested I will go ahead with the 3rd one -> 1 heap - 1 list as we need to free the heap after the read is successful in the next module.