twitter
    Find out what I'm doing, Follow Me :)

More About Segments

This section applies only to MS-DOS users, and is a consequence of the brain damaged segmented design of the Intel 8086 processor. The design was forced upon Intel by a commercial requirement that they remain semi-compatible with their first microprocessors, the 8008 and 8080. This segmentation forces a choice of memory models on MS-DOS users, which their compilers try to make somewhat easier. This limitation was only overcome with the release of Intel 80386 and later processors, which can have large segments.

Someof the moreexpensive compilers give the user a choice ofmemorymodels to use. Examples are Lattice and Microsoft, which allow the programmer a choice of using a model with a 64K limitation on program size but more efficient running, or using a model with a 640K limitation and requiring longer address calls leading to less efficient addressing. Using the larger address space requires inter segment addressing resulting in the slightly slower running time. The time is probably insignificant in most programs, but there are other considerations. If an MS-DOS program uses no more than 64K bytes for the total of its code and memory and if it doesn’t use a stack, it can be made into a .com file. Since a .com file is already in a memory image format, it can be loaded very quickly whereas a file in a .exe format must have its addresses relocated as it is loaded. Therefore a small memory model can generate a program that loads faster than one generated with a larger memory model. Don’t let this worry you, it is a fine point that few programmers worry about.

Using dynamic allocation, it is possible to store the data on the "heap" and that may be enough to allow you to use the small memory model. Of course, you wouldn’t store local variables such as counters and indexes on the heap, only very large arrays or structures. Even more important than the need to stay within the small memory model is the need to stay within the computer. If you had a program that used several large data storage areas, but not at the same time, you could load one block storing it dynamically, then get rid of it and reuse the space for the next large block of data. Dynamically storing each block of data in succession, and using the same storage for each block may allow you to run your entire program in the computer without breaking it up into smaller programs.