3.1 _amblksiz

The _amblksiz variable controls memory heap granularity.

It is declared in the MALLOC.H include file as follows:

extern unsigned int _amblksiz;

The value of _amblksize is used to control how memory is obtained from the operating system for the heap. The initial requested size for a segment of memory for the heap manager is based on the amount of current allocation request plus overhead for the heap manager's bookkeeping chores—that is, just enough to satisfy the allocation request at hand (for example, a malloc or calloc). However, when the heap manager grows a segment, it does so in multiples of _amblksize. The value of _amblksize represents a trade-off between the number of times the operating system must be called to grow a segment to its maximum size (no more than 640K for DOS) and the amount of memory potentially wasted (available but not used) at the end of the heap.

The default value of _amblksize is 8K. The value can be changed by direct assignment in your program. For example:

_amblksize = 2048;

The actual value used internally by the heap manager will be the given value, rounded up to the nearest whole power of 2 (so an _amblksize value of 4K–1 is the same as a value of 4K).

Note that adjusting the value of _amblksize affects allocation in the near, far, and based heaps. The value of _amblksize has no effect on huge memory blocks (those allocated with _halloc and similar functions).