Chapter Contents

Previous

Next
SIGFPE

New Multiple Heap Functions

Several new functions have been added allow a program to make use of more than one heap. All programs contain at least 2 heaps; a library heap and a standard heap. Library routines that need dynamic memory will allocate from the library heap. Normally, this memory is internally used and not accessable to the user. The standard heap is where memory will be allocated from by calls to malloc, pool, calloc etc. This heap can be predefined with attributes other than the default. At program start, the standard heap is also the default heap. Additional heaps can be created and declared as the default heap by pushing the new heap onto the heap stack. Calls to malloc calloc, free, pool, realloc (For brevity, the rest of this description will use malloc as the general term for getting heap memory.) will allocate memory from whatever is the current default heap. Additional functions are available to get memory from a specific heap without making it the default heap.

A heap is represented by a heap ID, which is an opaque token returned by the hpcreate function. hpcreate is passed a heap attribute structure, which defines the required behavior and properties of the heap. multheap.h defines the various attributes that can be set for a heap. These include location in memory (that is, above or below the bar/line) subpool number, initial and overflow sizes, whether the heap can be shared between subtasks and more. For above the bar heaps (heaps with virtual addresses greater than 2G), the maximum guaranteed size of the heap is 2G, although the heap may reach a hard limit of 4G. If more than 2G of contiguous memory is needed, then the IARV64 function should be used.

The attributes of the standard heap can be set by defining an external variable _heapdef and initializing it with the required attributes. For example, to have the standard heap be placed above the 2G bar, specify:

extern _heap_attr _heapdef = {0, 0, 0, 0, 0, 0, HPLOC_64}

Attributes specified in this way override those set through previous methods (the _heap variable and the =/mmm runtime option).


_heap_attr

The _heap_attr structure in multheap.h defines the attributes of a heap. This structure is passed to hpcreate to create a new heap with these characteristics.

int version;
version number set by call to hpattr.

int flags;
Miscellaneous flags to represent heap attributes.

HPATTR_SHARED
Indicates that the heap can be shared between cooperating subtasks. Memory can be passed from one subtask to another and the receiver can then free the memory. Care must be taken however to serialize access to the memory. If more than one subtask updates the memory at the same time, results are unpredictable. The library serializes the allocation and deallocation of this memory.

HPATTR_ZERO
Indicates that the heap will be initialized to all zeros before it is passed to the user program.

HPATTR_NOUSAGE
Indicates that the heap will not be included in any usage report. See =usage for more information.

HPATTR_NOABEND
Indicates that eyecatchers in heap control blocks will not be checked. Normally, if the eyecatchers are overlayed or storage pointers are corrupted, the library will an ABEND in the range of U1205-U1209. Setting this attribute will let the program proceed without abending in the event of a storage overlay. This option should only be used for programs where an ABEND would have a significantly worse consequence than running with bad data.

HPATTR_RETAIN
Indicates that the heap will not be returned to the operating system until a call is made to hpdestroy.

HPATTR_SIGOK
Indicates that the heap will be eligible for use in signal handling code. If malloc is called from a signal handler and the default heap does not have this indication, then the most recent heap created with this indication will be used for allocation. The non-shared heap list is searched before looking at the shared heaps.

char *area;
If not NULL, then initial allocations will be taken from the memory addressed by area. This in effect allows a heap within a heap. There is no protection against the owner of this area freeing the storage so care must be taken when using this field. The envisioned use of this would be for a number of callers to be able to use separate heaps without the overhead of getting the memory directly from the operating system. Rather, a large allocation would be done for all of the callers and multiple virtual heaps would be created from that area.

unsigned int initial;
Size of the initial heap allocation. It must be greater than 0.

unsigned int overflow;
Size for needed additional allocations. The default is 4K. If it is set to 0, then no secondary allocations will be performed. That is, any mallocs beyond the initial amount will fail.

int subpool;
In MVS, the subpool (if it is below the bar) to allocate from. If it is not specified, 13 will be assumed unless the heap is to be shared, in which case the default subpool is 131.

char amode;
Intended addressing mode of the user. Determines the location of the allocated memory in the address space. Only HPLOC_64 will get memory above the 2G bar.

HPLOC_BELOW
Memory will be allocated below the 16M line.

HPLOC_ANY
Memory will be allocated above the 16M line if possible, otherwise from below the 16M line.

HPLOC_64
Memory will be above the 2G bar.

HPLOC_RES
Memory will be allocated below the 16M line for callers running AMODE24. And above the line for callers running AMODE31 or AMODE64. If memory is not available above the line, an attempt will be made to allocate memory below the line.


Chapter Contents

Previous

Next

Top of Page

Copyright © 2004 by SAS Institute Inc., Cary, NC, USA. All rights reserved.