Microsoft has not officially documented the internal structure of arena headers for the outside world at present. This is probably to deter programmers from trying to manipulate their memory allocations directly instead of through the MS-DOS functions provided for that purpose.
Arena headers have identical structures in MS-DOS versions 2 and 3. They are 16 bytes (one paragraph) and are located immediately before the memory area that they control (Figure 11-3). An arena header contains the following information:
A byte signifying whether the header is a member or the last entry in the entire chain of such headers
A word indicating whether the area it controls is available or whether it already belongs to a program (if the latter, the word points to the program's PSP)
A word indicating the size (in paragraphs) of the controlled memory area (arena entry)
MS-DOS inspects the chain of arena headers whenever the program requests a memory-block allocation, modification, or release function, or when a program is EXEC'd or terminated. If any of the blocks appear to be corrupted or if the chain is broken, MS-DOS displays the dreaded message
Memory allocation error
and halts the system.
In the example illustrated in Figure 11-3, COMMAND.COM originally loaded PROGRAM1.COM into the TPA and, because it was a .COM file, COMMAND.COM allocated it all of the TPA, controlled by arena header #1. PROGRAM1.COM then used Int 21H Function 4AH (Resize Memory Block) to shrink its memory allocation to the amount it actually needed to run and loaded and executed PROGRAM2.EXE with the EXEC function (Int 21H Function 4BH). The EXEC function obtained a suitable amount of memory, controlled by arena header #2, and loaded PROGRAM2.EXE into it. PROGRAM2.EXE, in turn, needed some additional memory to store some intermediate results, so it called Int 21H Function 48H (Allocate Memory Block) to obtain the area controlled by arena header #3. The highest arena header (#4) controls all of the remaining TPA that has not been allocated to any program.
Figure 11-3. An example diagram of MS-DOS arena headers and the transient-program area. The environment blocks and their associated headers have been omitted from this figure to increase its clarity.
Please refer to the printed book for this figure.