Wednesday 16 November 2011

What are the differences between the memory models? in C programming

What are the differences between the memory models?

DOS uses a segmented architecture to address your computer’s memory. For each physical memory location, it has an associated address that can be accessed using a segment-offset method. To support this segmented architecture, most C compilers enable you to create your programs using any of the six memory models listed

Memory             Model Limits                                          Pointer Usage
----------------------------------------------------------------------------------------------------------------
Tiny                  Code, data, and stack—64KB                   Near
Small                 Code—64KB                                          Near
                         Data and stack—64KB                            Near
Medium             Code—1 megabyte                                  Far
                         Data and stack—64KB                            Near
Compact            Code—64KB                                          Near
                         Data and stack—1 megabyte                   Far
Large                 Code—1 megabyte                                 Far
                         Data and stack—1 megabyte                   Far
Huge*                Code—1 megabyte                                 Far
                         Data and stack—1 megabyte                   Far

* Note that in the Huge memory model, static data (such as an array) can be larger than 64KB.
This is not true in all the rest of the memory models.

The Tiny memory model is extremely limited (all code, data, and stack must fit in 64KB); it is most often used for the creation of .COM files. The Huge memory model imposes a significant performance penalty because of the way it has to “fix up” memory addresses; it is rarely used.

Cross Reference:

XVIII.3: What are the most commonly used memory models?
XVIII.4: Which memory model should be used?

No comments:

Post a Comment