home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / MCB.ZIP / MCB.TXT < prev   
Encoding:
Text File  |  1988-11-25  |  24.8 KB  |  460 lines

  1. ----------------------------------------------------------------------
  2.  
  3.                         Text of the article:
  4.  
  5.                   MAPPING DOS MEMORY ALLOCATION
  6.  
  7.  
  8.    The concept of a memory control block (MCB) was introduced in MS-DOS,
  9. Version 2.0, as the operating system's basic method of tracking memory 
  10. allocation for application programs and installable device drivers. In this 
  11. article, I'll discuss how DOS uses memory control blocks and will present a 
  12. Turbo C (typist used Power C) program named MCB.C that prints out DOS' current 
  13. state of memory allocation. First, it might be useful to review how the PC 
  14. uses memory.
  15.  
  16.    Address (Hex)     Memory Usage
  17.  _______________________________________________________________
  18. |                |                                              |
  19. |   0000:0000    |   Interrupt vector table                     |
  20. |   0040:0000    |   ROM BIOS data area                         |
  21. |   0050:0000    |   DOS parameter area                         |
  22. |   0070:0000    |   IBMBIO.COM / IO.SYS    (See note 1 below)  |
  23. |   mmmm:mmmm    |   IBMDOS.COM / MSDOS.SYS (See note 1 below)  |
  24. |   mmmm:mmmm    |   CONFIG.SYS - specified information         |
  25. |                |   (device drivers and internal buffers)      |
  26. |   mmmm:mmmm    |   Resident COMMAND.COM                       |
  27. |   mmmm:mmmm    |   Master environment                         |
  28. |   mmmm:mmmm    |   Environmrnt block # 1                      |
  29. |   mmmm:mmmm    |   Application program # 1                    |
  30. |       .        |            .                                 |
  31. |       .        |            .                                 |
  32. |       .        |            .                                 |
  33. |   mmmm:mmmm    |   Environment block # n                      |
  34. |   mmmm:mmmm    |   Application # n                            |
  35. |   xxxx:xxxx    |   Transient COMMAND.COM                      |
  36. |   A000:0000    |   Video buffers and ROM                      |
  37. |   FFFF:000F    |   Top of 8086 / 88 address space             |
  38. |----------------|----------------------------------------------|
  39. |  Note 1: PC-DOS uses IBMBIO.COM and IBMDOS.COM                |
  40. |          MS-DOS uses IO.SYS and MSDOS.SYS instead.            |
  41. |---------------------------------------------------------------|
  42.  
  43.    FIGURE 1: The PC memory map
  44.  
  45.    Figure 1 shows the major aspects of the PC memory map as documented by
  46. Microsoft and IBM. Addresses are shown in hexadecimal segment:offset form. 
  47. Numeric addresses give absolute memory locations for those items that are 
  48. always invariant in a PC running under MS-DOS, Versions 2.0 and later. 
  49. Symbolic addresses vary according to the version of DOS you are running and 
  50. the number and types of applications presently in memory. More than one 
  51. program will be in memory if one or more terminate-and-stay-resident (TSR) 
  52. program has been installed.
  53.    The program MCB.C in Listing One, page 94, computes and prints out specific 
  54. addresses shown as mmmm:mmmm in Figure 1, which includes most of the unknowns 
  55. in the DOS memory map. The only address it cannot compute is the starting 
  56. address of the transient portion of COMMAND.COM (denoted by address 
  57. xxxx:xxxx). MCB.C also provides insight as to how the DOS memory management 
  58. functions do their job and can show you exactly where all your memory has gone 
  59. the next time you run out of it on a machine overloaded with TSR's. Finally, 
  60. MCB.C should give you ideas about how to reallocate memory appropriately 
  61. should it become necessary. For now, I'll discuss DOS memory control blocks 
  62. and describe where they fit it into all this.
  63.  
  64. MEMORY CONTROL BLOCKS
  65.    Microsoft and IBM document the fact that they use MCB's, but neither docu-
  66. ments specific details of how they use them. The contents of an MCB, also 
  67. known as an arena header, are illustrated in figure2, page 57. An MCB contains 
  68. three fields called the chain id, process ID (PID), and block size. Together 
  69. these fields occupy the first 5 bytes of the MCB; the remaining 11 bytes are 
  70. unused. An MCB always begins on a paragraph boundary and occupies exactly one 
  71. paragraph (16 bytes) of memory. The chain id byte indicates whether this is 
  72. the last MCB (value Z) or if another follows (value M). The memory block 
  73. controlled by a given MCB always follows immediately, starting at the next 
  74. paragraph, and has a size equal to the number of paragraphs specified in the 
  75. block-size field of the MCB. I'll refer to these blocks of memory as memory 
  76. blocks (MB's) to distinguish them from the MCB's. Subsequent MCB/MC pairs 
  77. always start just after the previous pair. MCB's can be thought of as a 
  78. forward-linked-list data structure, with the MB's they control neatly 
  79. sandwiched in between. In normal operation, there are no gaps in this 
  80. structure. If DOS detects any corruption in the MCB chain, it prints out an 
  81. error message and halts the system. (I have had occasion to break the MCB 
  82. chain deliberately during my investegations; DOS doesn't always notice.)
  83.  
  84.  ______________________________________________________________________
  85. |                                                                      |
  86. |  MCB                                                                 |
  87. |  Start                Memory Control Block Fields                    |
  88. |  Address     ___________________________________________________     |
  89. |              |  chain   |  PID  |  blk   |  unused             |     |
  90. |  yyy0:000    |    id    |       |  size  |                     |     |
  91. |              |-------------------------------------------------|     |
  92. |                                                                      |
  93. |  Offset ------>   0        1-2     3-4      5-15                     |
  94. |                                                                      |
  95. |                                                                      |
  96. |      where chain id = MCB chain-identification byte. Its value is    |
  97. |                       Z for the last MCB in DOS' MCB chain and       |
  98. |                       M otherwise                                    |
  99. |                                                                      |
  100. |                 PID = Process ID, or the program segment             |
  101. |                       prefix of the program that 'owns' the          |
  102. |                       MCB and the memory it controls.                |
  103. |                                                                      |
  104. |            blk size = Size of the contiguous block of memory         |
  105. |                       controlled by the MCB in units of              |
  106. |                       paragraphs. It does not include the MCB        |
  107. |                       itself.                                        |
  108. |----------------------------------------------------------------------|
  109.  
  110.    FIGURE 2: MCB fields
  111.  
  112.    The first MCB/MB pair allocated by DOS is always owned by IBMDOS.COM/
  113. MSDOS.SYS and is the fifth PC memory region, as shown in Figure 1. The number 
  114. of remaining MCB's depends upon whether or not any TSR's have been installed. 
  115. Typically, any program (transient or TSR) in memory owns at least two MCB's - 
  116. one for its copy of the environment and the other for its code and data. If 
  117. the program has allocated additional space (for example as internal buffer 
  118. space), it may own more MCB's. If a TSR has freed its environment block (as 
  119. some do), it may own only one MCB. 
  120.  
  121. DOS MEMORY-MANAGEMENT FUNCTIONS
  122.    Starting with Version 2.0, all versions of DOS contain functions to
  123. allocate memory (function 48H), free allocated memory (FUNCTION 49h), and 
  124. modify allocated memory (function 4aH). None of these functions deal directly 
  125. with MCB's; instead they deal with the associated MB's. Changes caused by use 
  126. of these functions, however, are reflected in the MCB's as can be seen upon 
  127. inspection (using my program) after use of any of these functions. In 
  128. addition, DOS 3.x provides function 58h (get/change memory allocation 
  129. strategy), which controls how memory is allocated: first fit (the default in 
  130. DOS 3.x and that used in DOS 2.x); last fit; and best fit.
  131.    Note that DOS (actually COMMAND.COM) uses these functions to allocate 
  132. two memory blocks automatically when it loads and runs a transient program 
  133. (using the DOS EXEC function 4bH) and frees them upon termination. Any other 
  134. memory allocated by an application using these functions must subsequently be 
  135. freed or it will remain in memory. None of the memory allocated for a TSR is 
  136. released automatically, of course.
  137.    A more detailed discussion of these memory-management functions would
  138. warrant a separate article. After using my program, all of them should make 
  139. more sense (the official documentation for them is a little cryptic). Also, 
  140. with the understanding of DOS memory allocation provided by my program and 
  141. this article, DOS could be bypassed altogether for memory management, although 
  142. that is not my intention.
  143.  
  144. LOCATING MCB's IN MEMORY 
  145.    Two of a program's MCB's can be found easily: one MCB is one paragraph
  146. above its PSP; the other is one paragraph above the environment block. The 
  147. segment address of the copy of the environment is contained in the word at 
  148. offset 2cH in the PSP. (This is not true for the master copy of COMMAND.COM. 
  149. Under DOS 2.0-3.2, the environment pointer for the master copy of COMMAND.COM 
  150. has a dummy value of 0000. DOS 3.3 corrects this oversight.) This doesn't help 
  151. you find the MCB's lower in memory, though, because the MCB's are linked only 
  152. in the forward direction. The trick is to locate the first MCB in memory-once 
  153. you have done that, it is a simple matter to visit them all.
  154.    So how do you find the first MCB? There is no documented way. Any number of 
  155. brute-force methods have occurred to me, none of them very satisfactory. 
  156. Fortunately, there is a better method that involves the undocumented DOS 
  157. Invars function 52H. When this function call is complete, ES:[BX-2] points to 
  158. a word that contains the segment address of the first MCB. Because all MCB's 
  159. start on a paragraph boundary, that's all you need to locate the first one.
  160.  
  161. OBTAINING ADDITIONAL INFORMATION 
  162.    Each MCB/MB pair is owned by a PID, which is nothing more than the segment 
  163. address of the PSP of the program that owns the memory. From the PSP address, 
  164. you can derive other useful information. First, you can find the location of 
  165. the program's copy of the environment, as mentioned earlier. Another 
  166. (undocumented) piece of information you can discover is the PID of the parent 
  167. process, which is located at the word PSP:16H. In DOS 3.x only, you can also 
  168. find the name of the owner program.
  169.    The PID owner name consists of the drive, path, and filename of the pro-
  170. gram allociated with the PID. To find it, first locate the copy of the 
  171. environment for any program other than the operating system files IBMDOS.COM 
  172. and COMMAND.COM (these must be treated separately) using the word at PID:2Ch. 
  173. Each string in the environment is in ASCIIZ form (which ends in a NULL, the 
  174. ASCII character with value 0). Search for the first double NULL (sometimes 
  175. there is more than one).
  176.    If a word count of 0001 immediately follows the double NULL (indicating 
  177. that only one more ASCIIZ string is left in the environment), then the owner 
  178. of the program is given by the ASCIIZ string immediately following. If the end 
  179. of the environment is reached and no such pattern is found, the owner is 
  180. unknown. (This will always be the case for DOS 2.x) Note that if a TSR has 
  181. freed its environment block, the owner name thus found is likely to be
  182. inaccurate because the TSR no longer owns it and it may have been claimed by a 
  183. different program (typically, the next TSR or transient program will claim 
  184. it).
  185.  
  186. THE MCB PROGRAM 
  187.    The procram MCB.C in listing One is heavily commented, so I'll make only
  188. a few general comments here.
  189.    I used the small-memory model of Turbo C, Version 1.5, (as mentioned before
  190. the typist used Power C) to compile and link MCB.C into MCB.EXE. The 
  191. complications of doing so are manifested in the explicit declarations of some 
  192. far and huge pointers, as explained in the comments.
  193.    I used no Turbo C library calls specific to either Turbo C itself or to
  194. the IBM PC, so other C compilers should have no problem compiling the program, 
  195. and it should run on any MS-DOS machine, even one not compatible with the IBM 
  196. PC. (I ran it without any difficulty on a DEC Rainbow under MS-DOS 2.11.)
  197. (Typist note: See the file MCB_READ.ME for a problem I encountered in 
  198. compiling with Quick C)
  199.    The program itself is a straightforward implementation using the material
  200. discussed earlier in this article. The first MCB in memory is located using 
  201. DOS function 52h. The program then visits each one and computes and prints out 
  202. information on each MCB/MB. See the large comment block at the end of function 
  203. prn_header() in Listing One (the MCB.C program) for a detailed description of 
  204. the fields printed for each MCB.
  205.    Examples 1-6, pages 57-63, contain the screen output of several 
  206. illustrative examples. The conditions under which each was run are summarized 
  207. in the captions. The effects of other DOS commands run are also shown when 
  208. they are relevant to the discussion.
  209.    Example 1 illustrates the minimum number of MCB/MB pairs because no extra
  210. device drivers or TSR's have been installed. The curious free embedded MCB 03 
  211. seems to be a leftover from the DOS boot process-it seems strange that DOS 
  212. should leave it there. Also note the use of memory by MCB.EXE and the final 
  213. large free block. Many application programs claim all of the remaining memory 
  214. for themselves when they run, and I was curious as to why MCB.EXE didn't. 
  215. Because it was an .EXE file, it was possible that its .EXE header specified a 
  216. smaller amount of memory. I checked the header and found it was set to claim 
  217. as much free memory as was available. I finally traced the return of memory to 
  218. DOS by examining the Turbo C start-up code that was executed prior to giving 
  219. main() control. Sure enough, this code called DOS function 4Ah. The parent 
  220. address (022Bh) of IBMDOS.COM in this example is also interesting.
  221.  
  222. C>mcb
  223.  
  224. ====================================================================
  225. MCB MCB  ID PID    MB   PAR- ENV  OWNER
  226. NO. SEG            SIZE ID   BLK?
  227. ====================================================================
  228. 01  0973 M  008    8208 022B N    IBMDOS.COM/MSDOS.SYS
  229. 02  0B75 M  0B76   3376 0B76 N    COMMAND.COM COPY # 1
  230. 03  0C49 M  0000     48 F000 N    FREE MEMORY CONTROL BLOCK
  231. 04  0C4D M  0B76    160 0B76 N    COMMAND.COM COPY # 1
  232. 05  0C58 M  0C5E     64 0B76 Y    C:\TURBOC\DEV\MCB.EXE
  233. 06  0C5D M  0C5E  71232 0B76 N    C:\TURBOC\DEV\MCB.EXE
  234. 07  1DC2 Z  0000 530384 F000 N    FREE MEMORY CONTROL BLOCK
  235. ====================================================================
  236. Example 1: System booted with no CONFIG.STS and no AUTOEXEC.BAT. (I
  237. was in the directory C:\TURBOC\DEV, where MCB.EXE resides on my system,
  238. for this and all subsequent examples.)
  239.  
  240.    In Example 2, the size of the MB controlled by MCB 01 and owned by
  241. IBMDOS.COM shows an increase of 8,144 bytes. The extra space was allocated 
  242. during the boot process in response to the statements in CONFIG.SYS. These 
  243. statements caused extra storage to be allocated for the installation of the 
  244. device driver ANSI.SYS as well as that needed to carry out the FILES=50 and 
  245. BUFFERS=20 commands. This block grows much larger when VDISK.SYS is 
  246. installed. Try it.
  247.  
  248.  
  249. C>type \config.sys
  250.   device=c:\dos\ansi.sys
  251.   files=50
  252.   buffers-20
  253.   lastdrive=z
  254.  
  255. C>mcb
  256.  
  257. ====================================================================
  258. MCB MCB  ID PID    MB   PAR- ENV  OWNER
  259. NO. SEG            SIZE ID   BLK?
  260. ====================================================================
  261. 01  0973 M  0008  16352 022B N    IBMDOS.COM/MSDOS.SYS
  262. 02  0D72 M  0D73   3376 0D73 N    COMMAND.COM COPY # 1
  263. 03  0E46 M  0000     48 F000 N    FREE MEMORY CONTROL BLOCK
  264. 04  0E4A M  0D73    160 0D73 Y    COMMAND.COM COPY # 1
  265. 05  0E55 M  0E5B     64 0D73 Y    C:\TURBOC\DEV\MCB.EXE
  266. 06  0E5A M  0E5B  71232 0D73 N    C:\TURBOC\DEV\MCB.EXE
  267. 07  1FBF Z  0000 522240 F000 N    FREE MEMORY CONTROL BLOCK
  268. ====================================================================
  269. Example 2: The PC rebooted with the CONFIG.SYS shown and no AUTOEXEC.BAT
  270.  
  271.  
  272.    In Example 3, the DOS 3.3 command FASTOPEN is seen to be a memory-resident 
  273. program that owns two blocks of memory-one for a copy of the environment and 
  274. one for the resident code itself, which is the typical case.
  275.  
  276.  
  277. C>type \autoexec.bat
  278.   path c:\dos;c:\util;c:\turboc;c:\util\norton;c:\masm;c:\pe
  279.   prompt $p$g
  280.   mgc
  281.   astclock
  282.   subst u: c:\util
  283.   fastopen c:
  284.   cls
  285.  
  286. C>mcb
  287.  
  288. ====================================================================
  289. MCB MCB  ID PID    MB   PAR- ENV  OWNER
  290. NO. SEG            SIZE ID   BLK?
  291. ====================================================================
  292. 01  0973 M  0008  16352 022B N    IBMDOS.COM/MSDOS.SYS
  293. 02  0D72 M  0D73   3376 0D73 N    COMMAND.COM COPY # 1
  294. 03  0E46 M  0000     48 F000 N    FREE MEMORY CONTROL BLOCK
  295. 04  0E4A M  0D73    160 0D73 Y    COMMAND.COM COPY # 1
  296. 05  0E55 M  0E5F    128 0D73 Y    C:\DOS\FASTOPEN.EXE
  297. 06  0E5E M  0E5F   2896 0D73 N    C:\DOS\FASTOPEN.EXE
  298. 07  0F14 M  0F1E    128 0D73 Y    C:\TURBOC\DEV\MCB.EXE
  299. 08  0F1D M  0F1E  71232 0D73 N    C:\TURBOC\DEV\MCB.EXE
  300. 09  2082 Z  0000 519120 F000 N    FREE MEMORY CONTROL BLOCK
  301. ====================================================================
  302. Example 3: The PC rebooted with the CONFIG.SYS in Example 2 and an
  303. AUTOEXEC.BAT file with the contents shown.
  304.  
  305.  
  306.    Example 4 shows that the DOS GRAPHICS command is also a TSR and that it
  307. owns two more blocks of memory. Some TSR programs free their copy of the 
  308. environment before executing the DOS TSR function. Such programs will not only 
  309. have no environment block but also the owner of the remaining block holding 
  310. the resident code may be incorrect because the owner string resides in the 
  311. freed environment block. A TSR may have also allocated additional memory 
  312. before exiting to DOS, in which case it would own additional memory blocks, 
  313. which MCB.EXE would report.
  314.  
  315. C>graphics
  316.  
  317. C>mcb
  318.  
  319. ====================================================================
  320. MCB MCB  ID PID    MB   PAR- ENV  OWNER
  321. NO. SEG            SIZE ID   BLK?
  322. ====================================================================
  323. 01  0973 M  0008  16352 022B N    IBMDOS.COM/MSDOS.SYS
  324. 02  0D72 M  0D73   3376 0D73 N    COMMAND.COM COPY # 1
  325. 03  0E46 M  0000     48 0F14 N    FREE MEMORY CONTROL BLOCK
  326. 04  0E4A M  0D73    160 0D73 Y    COMMAND.COM COPY # 1
  327. 05  0E55 M  0E5F    128 0D73 Y    C:\DOS\FASTOPEN.EXE
  328. 06  0E5E M  0E5F   2896 0D73 N    C:\DOS\FASTOPEN.EXE
  329. 07  0F14 M  0F1E    128 0D73 Y    C:\DOS\GRAPHICS.COM
  330. 08  0F1D M  0F1E   2144 0D73 N    C:\DOS\GRAPHICS.COM
  331. 09  0FA4 M  0FAE    128 0D73 Y    C:\TURBOC\DEV\MCB.EXE
  332. 10  0FAD M  0FAE  71232 0D73 N    C:\TURBOC\DEV\MCB.EXE
  333. 11  2112 Z  0000 516816 0F14 N    FREE MEMORY CONTROL BLOCK
  334. ====================================================================
  335. Example 4: Running the DOS command GRAPHICS
  336.  
  337.  
  338.    In Example 5, the secondary copy of COMMAND.COM owns three blocks of memory 
  339. for some reason. I don't know why, but it's interesting.
  340.  
  341. C>command
  342.  
  343. The IBM Personal Computer DOS
  344. Version 3.30 (C)Copyright International Business Machines Corp 1981,1987
  345.              (C)Copyright Microsoft Corp 1981, 1986
  346.  
  347. C>mcb
  348.  
  349. ====================================================================
  350. MCB MCB  ID PID    MB   PAR- ENV  OWNER
  351. NO. SEG            SIZE ID   BLK?
  352. ====================================================================
  353. 01  0973 M  0008  16352 022B N    IBMDOS.COM/MSDOS.SYS
  354. 02  0D72 M  0D73   3376 0D73 N    COMMAND.COM COPY # 1
  355. 03  0E46 M  0000     48 0F14 N    FREE MEMORY CONTROL BLOCK
  356. 04  0E4A M  0D73    160 0D73 Y    COMMAND.COM COPY # 1
  357. 05  0E55 M  0E5F    128 0D73 Y    C:\DOS\FASTOPEN.EXE
  358. 06  0E5E M  0E5F   2896 0D73 N    C:\DOS\FASTOPEN.EXE
  359. 07  0F14 M  0F1E    128 0D73 Y    C:\DOS\GRAPHICS.COM
  360. 08  0F1D M  0F1E   2144 0D73 N    C:\DOS\GRAPHICS.COM
  361. 09  0FA4 M  0FAD    112 0FAD N    COMMAND.COM COPY # 2
  362. 10  0FAC M  0FAD   3376 0FAD N    COMMAND.COM COPY # 2
  363. 11  1080 M  0FAD    160 0FAD Y    COMMAND.COM COPY # 2
  364. 12  108B M  1095    128 0FAD Y    C:\TURBOC\DEV\MCB.EXE
  365. 13  1094 M  1095  71232 0FAD N    C:\TURBOC\DEV\MCB.EXE
  366. 14  21F9 Z  0000 513120 0F14 N    FREE MEMORY CONTROL BLOCK
  367. ====================================================================
  368. Example 5: Installing a secondary copy of COMMAND.COM
  369.  
  370.  
  371.    Example 6 shows that the space formerly occupied by the secondary 
  372. COMMAND.COM has been freed upon execution of the EXIT command. You can install 
  373. more than one secondary COMMAND.COM if desired, and you can remove each one in 
  374. reverse order with an EXIT command.
  375.  
  376. C>exit
  377.  
  378. C>mcb
  379.  
  380. ====================================================================
  381. MCB MCB  ID PID    MB   PAR- ENV  OWNER
  382. NO. SEG            SIZE ID   BLK?
  383. ====================================================================
  384. 01  0973 M  0008  16352 022B N    IBMDOS.COM/MSDOS.SYS
  385. 02  0D72 M  0D73   3376 0D73 N    COMMAND.COM COPY # 1
  386. 03  0E46 M  0000     48 0F14 N    FREE MEMORY CONTROL BLOCK
  387. 04  0E4A M  0D73    160 0D73 Y    COMMAND.COM COPY # 1
  388. 05  0E55 M  0E5F    128 0D73 Y    C:\DOS\FASTOPEN.EXE
  389. 06  0E5E M  0E5F   2896 0D73 N    C:\DOS\FASTOPEN.EXE
  390. 07  0F14 M  0F1E    128 0D73 Y    C:\DOS\GRAPHICS.COM
  391. 08  0F1D M  0F1E   2144 0D73 N    C:\DOS\GRAPHICS.COM
  392. 09  0FA4 M  0FAE    128 0D73 Y    C:\TURBOC\DEV\MCB.EXE
  393. 10  0FAD M  0FAE  71232 0D73 N    C:\TURBOC\DEV\MCB.EXE
  394. 11  2112 Z  0000 516816 0F14 N    FREE MEMORY CONTROL BLOCK
  395. ====================================================================
  396. Example 6: The secondary COMMAND.COM remains in memory until a
  397.            DOS EXIT command is issued
  398.  
  399.  
  400.    In example 7, CHKDSK reports 588,064 bytes free, whereas in Example 6
  401. MCB shows 516,816 bytes free in the MB controlled by MCB 11. Let's reconcile 
  402. the differences. The free memory reported by CHKDSK is equal to 516,816 (MCB 
  403. 11) plus 16 plus 71,232 (MCB 10).
  404.    This makes sense. When CHKDSK runs, it has memory allocated to it (in
  405. fact all the remaining memory). When it reports the amount of free memory, it 
  406. subtracts the memory needed to run itself but does not discount that needed 
  407. for its copy of the environment, apparently reasoning that any program run 
  408. will need to have such an environment block allocated. The extra 16 bytes in 
  409. the equation above are needed to account for the paragraph of memory needed 
  410. for the last MCB (11 here) itself. Also note that CHKDSK does not include the 
  411. memory in any free memory embedded in the body of the allocation chain (such 
  412. as MCB 03), even though such memory is available for use under the right 
  413. conditions.
  414.  
  415.  
  416. C>chkdsk
  417.  
  418.    21309440 bytes total disk space
  419.    53248 bytes in 2 hidden files
  420.    59392 bytes in 28 directories
  421.    9635840 bytes in 580 user files
  422.    11560960 bytes available on disk
  423.  
  424.    652288 bytes total memory
  425.    588064 bytes free
  426.  
  427. EXAMPLE 7:Running the DOS command CHKDSK to see how much free memory it
  428. reports and see how it compares to that reproted by MCB.C
  429.  
  430.  
  431.    You'll also notece that the PC on which I ran this program seems to have
  432. only 652,360 bytes of total memory, which is 3,072 bytes less than the full 
  433. 640k (655,360 bytes) of memory that is actually installed. This is an example 
  434. of memory being hidden from DOS. My computer was an IBM PC XT equipped with a 
  435. Paradise graphics card (which provides for monochrome text and CGA graphics on 
  436. an IBM monochrome monitor). This video card also needs a memory-resident 
  437. program (called MGC.COM, see the contents of the AUTOEXEC.BAT file in Example 
  438. 3) installed in order for it to function. So why doesn't MGC.COM show up in 
  439. one of the MB's?
  440.    It occupies the top 3,072 bytes of memory. After installing itself it 
  441. modifies DOS' record of memory stored in word 40h:13h and does a warm reboot, 
  442. which reinitializes the computer without doing a memory check. The reason for 
  443. this procedure is that MGC.COM must be in memory even when DOS is not being 
  444. used (for example, for some games that need to be booted from a floppy). The 
  445. MCB/MB scheme is used only by DOS and wouldn't be sufficient in such cases.
  446.  
  447. CONCLUSION
  448.    The possible uses for this program are many. You could, for example, exam-
  449. ine the effect of all of the DOS memory-allocation functions detail. You could 
  450. possibly devise a scheme to remove any TSR from memory, not necessarily in 
  451. reverse of the order installed, without creating a hole in memory. With the 
  452. location of the master environment known, those who need to change the 
  453. environment frequently (for example the DOS path) and find the use of SET 
  454. tedious, could write a full-screen version of the DOS SET command. No doubt 
  455. you will think of other uses.
  456.  
  457.  
  458.                      END OF TEXT
  459.  
  460.