-

Changes

Jump to: navigation, search

Memory Models

62 bytes removed, 19:13, 30 July 2017
no edit summary
This concept of different address spaces is not catered
for by either K&R or ANSI C (except to recognize the possi-bility possibility of separate address spaces for code and data).
Without any extensions to the language itself it is possible
to devise more than one memory model for a given processor,
that program's memory requirements.
In many programs, however, only one or two data struc-tures structures are large enough to need to be placed in the larger
address space. Selection of a "large" memory model for the
whole of the program makes the whole program larger and
the following criteria:
1. # As far as possible the extensions should be consistentwith common practice. 2. # The extensions should fit a machine-independent modelto maximize portability across processors and operatingsystems.
These goals have been achieved within HI-TECH C by
Each memory model defines three address spaces
each for code and data. These address spaces are
known as the _�n_�e_�a_�r<strong>near, _�f_�a_�r far</strong> and _�d_�e_�f_�a_�u_�l_�t <strong>default</strong> spaces. Any
object qualified by the near keyword will be
placed in the _�n_�e_�a_�r <strong>near</strong> address space, any object qual-ified qualified by the far keyword shall be placed in the_�f_�a_�r <strong>far</strong> address space, and all other objects shall beplaced in the _�d_�e_�f_�a_�u_�l_�t <strong>default</strong> address space. The _�n_�e_�a_�r<strong>near</strong>address space shall be a (possibly improper) sub-space subspace of the _�d_�e_�f_�a_�u_�l_�t <strong>default</strong> address space, while the_�d_�e_�f_�a_�u_�l_�t <strong>default</strong> address space shall be a (possiblyimproper) subspace of the _�f_�a_�r <strong>far</strong> address space. Thereshall be up to three kinds of pointers correspond-ing corresponding to the three address spaces, each capable of
addressing an object in its own address space or a
subspace of that address space.
This implies that the address of an object may be con-verted converted to a pointer into a larger address space, e.g. a _�n_�e_�a_�r<strong>near</strong>object may have its address converted to a pointer to _�f_�a_�r<strong>far</strong>,but a _�f_�a_�r <strong>far</strong> object may not be able to be addressed by apointer to _�n_�e_�a_�r<strong>near</strong>.
In practice the _�d_�e_�f_�a_�u_�l_�t <strong>default</strong> address space will usuallycorrespond exactly to either the _�n_�e_�a_�r <strong>near</strong> or _�f_�a_�r <strong>far</strong> address spaces.
If all three address spaces correspond to the same memory
then there is only one memory model possible. This occurs
with the 68000 processor. Where the _�d_�e_�f_�a_�u_�l_�t <strong>default</strong> code and dataspaces may each correspond to either the _�n_�e_�a_�r <strong>near</strong> or _�f_�a_�r <strong>far</strong> address
spaces then there will be a total of four memory models.
This is the case with the 8086 processor.
described above.
This model also corresponds well with other implementa-tions implementations using the near and far keywords, although such imple-mentations implementations do not appear to have been designed around a for-malformal, portable model.

Navigation menu