Based Heaps

You can also allocate memory from a “based heap,” which is a single segment that lies outside the default data segment. Based-heap routines generally use the same names as standard memory routines, but begin with _b. For instance, _bmalloc allocates a memory block from the based heap and _bfree frees the block.

Based heaps offer the following advantages:

Localized data. Based heaps allow you to group related data in a single segment. This can simplify the management of related data.

Faster pointer arithmetic. Although the based heap lies in the far data segment, pointers to its data items are the same size as near pointers. Thus, pointer arithmetic on items in a based heap is faster than pointer arithmetic on items in the far heap.

The _bheapseg routine allocates a based heap segment, from which you can then allocate blocks of memory. You can call _bheapseg more than once to allocate as many based-heap segments as needed (within the confines of available memory).

The _bfreeseg routine frees a based-heap segment. This routine frees every block in the based-heap segment, whether or not you previously freed the blocks individually.

Note:

Near- , far- , and based-heap calls are not ANSI compatible and will make your program less portable.