Start of changeStart of change

Default Memory Manager

The default memory manager is a general-purpose memory manager which attempts to balance performance and memory requirements. It provides adequate performance for most applications while attempting to minimize the amount of additional memory needed.

The memory manager maintains the free space in the heap as nodes in a Cartesian binary search tree. This data structure imposes no limitation on the number of block sizes supported by the tree, allowing a wide range of potential block sizes.

Allocation

A small amount of additional memory is required for each allocation request. This additional memory is due to the need for a header on each allocation and the need for alignment of each block of memory. The size of the header on each allocation is 16 bytes. Each block must be aligned on a 16 byte boundary, thus the total amount of memory required for an allocation of size n is:

size = ROUND (n+16, 16)

For example, an allocation of size 37 would require a size of ROUND(37+16, 16), which is equal to 64 bytes.

A node of the tree that is greater than or equal to the size required is removed from the tree. If the block found is larger than the needed size, the block is divided into two blocks: one of the needed size, and the second a remainder. The second block is returned to the free tree for future allocation. The first block is returned to the caller.

If a block of sufficient size is not found in the free tree, the following processing occurs:

Deallocation

Memory blocks deallocated with the free operation are returned to the tree, at the root. Each node along the path to the insertion point for the new node is examined to see if it adjoins the node being inserted. If it does, the two nodes are merged and the newly merged node is relocated in the tree. If no adjoining block is found, the node is inserted at the appropriate place in the tree. Merging adjacent blocks is done to reduce heap fragmentation.

Reallocation

If the size of the reallocated block is larger than the original block, and the original block already has enough space to accommodate the new size (e. g. due to alignment requirements), the original block is returned without any data movement. If the size of the reallocated block is larger than the original block, the following processing occurs:

If the size of the reallocated block is smaller than the original block, and the difference in size is small, the original block is returned. Otherwise, if the size of the reallocated block is smaller than the original block, the block is split and the remaining portion is returned to the free tree.

Enabling the default memory manager

The default memory manager is enabled by default and can be configured by setting the following environment variables:

QIBM_MALLOC_TYPE=DEFAULT
QIBM_MALLOC_DEFAULT_OPTIONS=options

To specify user-specified configuration options for the default memory manager, set QIBM_MALLOC_DEFAULT_OPTIONS=options, where options is a blank delimited list of one or more configuration options.

If the QIBM_MALLOC_TYPE=DEFAULT environment variable is specified and the _C_Quickpool_Init() function is called, the environment variable settings take precedence over the _C_Quickpool_Init() function and the _C_Quickpool_Init() function returns a -1 value indicating that an alternate heap manager has already been enabled.

Configuration Options

The following configuration options are available:

MALLOC_INIT:N

This option can be used to specify that each byte of allocated memory is initialized to the given value. The value N represents an integer in the range of 0 to 255.

This option is not enabled by default.

FREE_INIT:N

This option can be used to specify that each byte of freed memory is initialized to the given value. The value N represents an integer in the range of 0 to 255.

This option is not enabled by default.

Any number of options can be specified and they can be specified in any order. Blanks are the only valid delimiter for separating configuration options. Each configuration option can only be specified once. If a configuration option is specified more than once, only the final instance applies. If a configuration option is specified with an invalid value, the configuration option is ignored.

Examples

ADDENVVAR ENVVAR(QIBM_MALLOC_DEFAULT_OPTIONS) LEVEL(*JOB) REPLACE(*YES) VALUE('')

ADDENVVAR ENVVAR(QIBM_MALLOC_DEFAULT_OPTIONS) LEVEL(*JOB) REPLACE(*YES) 
VALUE('MALLOC_INIT:255 FREE_INIT:0')

The first example represents the default configuration values. The second example illustrates all options being specified.

Related functions

There are no functions available to enable or specify configuration options for the default memory manager. The environment variable support must be used.

Related Information

End of changeEnd of change

[ Top of Page | Previous Page | Next Page | Contents | Index ]