__ucreate() — Create a heap using user-provided storage

Standards

Standards / Extensions C or C++ Dependencies
Language Environment both  

Format

#include <uheap.h>

__uheapid_t __ucreate(void *block,
                      size_t size,
                      __uheap_cellpool_attrib_table_t *cellpool_attrib_table,
                      void *rsvd1,
                      void *rsvd2,
                      void *rsvd3,
                      void *rsvd4);

General description

The __ucreate() function creates a heap out of storage that is provided by the caller. The heap is divided up into cell pools based on the information provided in the cellpool_attrib_table. Up to 12 cell pools can be created within the heap. Note that this is a fixed-size heap; when storage within a given cell pool is exhausted, no additional storage will be allocated. __ucreate() returns a uheapid that is used to identify the heap on subsequent user-created heap function calls, such as __umalloc(), __ufree(), and __uheapreport() calls.

Parameter
Description
block
A pointer to the storage which is to be used for the heap.
size
The size of the block of storage. Note that Language Environment reserves approximately 328 bytes of this storage for use in allocating heap management control blocks. Additional storage is reserved if storage report usage statistics are being collected for the heap. The amount of this storage is related to the largest cell size and the granularity of the statistics, and is calculated as: storage amount = ((largestcellsize+granularity-1)/granularity)*4.
cellpool_attrib_table
A pointer to a structure describing the attributes of the cell pools to be created by __ucreate().

The first field of the structure, number_of_pools, indicates the number of cell pools to be created. Up to 12 cell pools can be created in the heap.

The second field of the structure, granularity, indicates the granularity to which storage usage statistics is to be collected. This value must be zero, or a power of 2 greater than or equal to 8. If the value is zero, then statistics are not collected.

Following these words are pairs of words describing the attributes of each cell pool in the heap:

The first field in the pair, size, is the size of the cell in the cell pool. The cell size must be a multiple of 8 and greater than or equal to 8, up to a maximum of 64K (65536). Note that Language Environment adds an additional 8 bytes to the size of the cell for use in managing the cells. The second field in the pair, count, is the number of cells of this size to be allocated. Note the minimum is four.

rsvd1-rsvd4
Reserved for future use.

Returned value

If successful, __ucreate() returns a uheapid.

If unsuccessful, __ucreate() returns -1 and sets errno to EINVAL.

Related information