📄 wmodels.gml
字号:
.if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
:set symbol="function" value="function".
:set symbol="functions" value="functions".
.do end
.if '&lang' eq 'FORTRAN 77' .do begin
:set symbol="function" value="subprogram".
:set symbol="functions" value="subprograms".
.do end
.*
.chap *refid=mmodels Memory Models
.*
.section Introduction
.*
.np
This chapter describes the various memory models supported by
&cmpname..
Each memory model is distinguished by two properties; the code model
used to implement &function calls and the data model used to reference
data.
.*
.section Code Models
.*
.np
There are two code models;
.autopoint
.point
the small code model and
.point
the big code model.
.endpoint
.pc
:I1.small code model
:I1.code models:I2.small
:I1.near call
A small code model is one in which all calls to &functions are made
with
.us near calls.
In a near call, the destination address is 16 bits and is relative
to the segment value in segment register CS.
Hence, in a small code model, all code comprising your program,
including library &functions, must be less than 64K.
.if '&lang' eq 'FORTRAN 77' .do begin
&cmpname does not support the small code model.
.do end
.np
:I1.big code model
:I1.code models:I2.big
:I1.far call
A big code model is one in which all calls to &functions are made with
.us far calls.
In a far call, the destination address is 32 bits (a segment value and
an offset relative to the segment value).
This model allows the size of the code comprising your program to
exceed 64K.
.if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
.autonote Notes:
.note
If your program contains less than 64K of code, you should use a memory
model that employs the small code model.
This will result in smaller and faster code since near calls are
smaller instructions and are processed faster by the CPU.
.endnote
.do end
.*
.section Data Models
.*
.np
There are three data models;
.autopoint
.point
the small data model,
.point
the big data model and
.point
the huge data model.
.endpoint
.pc
:I1.small data model
:I1.data models:I2.small
A small data model is one in which all references to data are made
with
.us near pointers.
Near pointers are 16 bits;
all data references are made relative to the segment value in
segment register DS.
Hence, in a small data model, all data comprising your program must be
less than 64K.
.np
:I1.big data model
:I1.data models:I2.big
A big data model is one in which all references to data are made with
.us far pointers.
Far pointers are 32 bits
(a segment value and an offset relative to the segment value).
This removes the 64K limitation on data size imposed by the small
data model.
However, when a far pointer is incremented, only the offset is adjusted.
&cmpname assumes that the offset portion of a far pointer will not
be incremented beyond 64K.
The compiler will assign an object to a new segment if the grouping
of data in a segment will cause the object to cross a segment boundary.
Implicit in this is the requirement that no individual object
exceed 64K bytes.
For example, an array containing 40,000 integers does not fit into
the big data model.
An object such as this should be described as
.us huge.
.np
:I1.huge data model
:I1.data models:I2.huge
A huge data model is one in which all references to data are made
with far pointers.
This is similar to the big data model.
However, in the huge data model, incrementing a far pointer will
adjust the offset
.us and
the segment if necessary.
The limit on the size of an object pointed to by a far pointer
imposed by the big data model is removed in the huge data model.
.autonote Notes:
.if '&lang' eq 'FORTRAN 77' .do begin
.note
The huge data model has the same characteristics as the big data
model, but formal array arguments are assumed to exceed 64K bytes.
You should use the huge data model whenever any arrays in your
application exceed 64K bytes in size.
.do end
.note
If your program contains less than 64K of data, you should use the
small data model.
This will result in smaller and faster code since references using
near pointers produce fewer instructions.
.note
The huge data model should be used only if needed.
The code generated in the huge data model is not very efficient since
a run-time routine is called in order to increment far pointers.
This increases the size of the code significantly and increases
execution time.
.endnote
.*
.section Summary of Memory Models
.*
.np
As previously mentioned, a memory model is a combination of a code model
and a data model.
The following table describes the memory models supported by &cmpname..
.if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
:I1.tiny memory model
:I1.memory models:I2.tiny
:I1.small memory model
:I1.memory models:I2.small
:I1.compact memory model
:I1.memory models:I2.compact
.do end
:I1.medium memory model
:I1.memory models:I2.medium
:I1.large memory model
:I1.memory models:I2.large
:I1.huge memory model
:I1.memory models:I2.huge
.if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
.millust begin
Memory Code Data Default Default
Model Model Model Code Data
Pointer Pointer
-------- -------- -------- -------- --------
tiny small small near near
small small small near near
medium big small far near
compact small big near far
large big big far far
huge big huge far huge
.millust end
.do end
.if '&lang' eq 'FORTRAN 77' .do begin
.millust begin
Memory Code Data Default Default
Model Model Model Code Data
Pointer Pointer
-------- -------- -------- -------- --------
medium big small far near
large big big far far
huge big huge far huge
.millust end
.do end
.if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
.if '&machsys' ne 'QNX' .do begin
.*
.section Tiny Memory Model
.*
.np
In the tiny memory model, the application's code and data must total
less than 64K bytes in size.
All code and data are placed in the same segment.
Use of the tiny memory model allows the creation of a COM file for
the executable program instead of an EXE file.
For more information, see the section entitled
"Creating a Tiny Memory Model Application" in this chapter.
.do end
.do end
.*
.section Mixed Memory Model
.*
.np
:I1.mixed memory model
:I1.memory models:I2.mixed
A mixed memory model application combines elements from the various
code and data models.
.if '&lang' eq 'C' or '&lang' eq 'C/C++' .do begin
A mixed memory model application might be characterized as one that
uses the
.kw near,
.kw far
or
.kw huge
keywords when describing some of its &functions or data objects.
.do end
.if '&lang' eq 'FORTRAN 77' .do begin
A mixed memory model application might be characterized as one that
includes arrays which are larger than 64K bytes.
.do end
.np
For example, a medium memory model application that uses some
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -