This chapter describes the various 16-bit memory models supported by Watcom C/C++. Each memory model is distinguished by two properties: the code model used to implement function calls, and the data model used to reference data.
This chapter includes the following sections:
There are two code models:
There are three data models:
The compiler assigns an object to a new segment if the grouping of data in a segment causes 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 doesn't fit into the big data model. An object such as this should be described as huge.
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 Watcom C/C++.
Memory Model | Code Model | Data Model | Default Code Pointer | Default Data Pointer |
---|---|---|---|---|
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 |
A mixed memory model application combines elements from the various code and data models. A mixed memory model application might be characterized as one that uses the near, far, or huge keywords when describing some of its functions or data objects.
For example, a medium memory model application that uses some far pointers to data can be described as a mixed memory model. In an application such as this, most of the data is in a 64K segment (DGROUP), and hence can be referenced with near pointers relative to the segment value in segment register DS. This results in the generation of more efficient code, and better execution times than one can expect from a big data model. Data objects outside of the DGROUP segment are described with the far keyword.
Each memory model requires different run-time and floating-point libraries. Each library assumes a particular memory model, and should be linked only with modules that have been compiled with the same memory model. The following table lists the libraries that are to be used to link an application that has been compiled for a particular memory model.
Memory Model | Run-time Library | Floating-Point Calls Library | Floating-Point Library (80x87) |
---|---|---|---|
small | clibs.lib | maths.lib | math87s.lib, (no)emu87.lib |
medium | clibm.lib | mathm.lib | math87m.lib, (no)emu87.lib |
compact | clibc.lib | mathc.lib | math87c.lib, (no)emu87.lib |
large | clibl.lib | mathl.lib | math87l.lib, (no)emu87.lib |
huge | clibh.lib | mathh.lib | math87h.lib, (no)emu87.lib |
The following describes the segment ordering of an application linked by the Watcom Linker. Note that this assumes that the DOSSEG linker option has been specified.
A special segment belonging to class BEGDATA is defined when linking with Watcom run-time libraries. This segment is initialized with the hexadecimal byte pattern 01, and is the first segment in group DGROUP, so that storing data at location 0 can be detected.
Segments belonging to class BSS contain uninitialized data. Note that this only includes uninitialized data in segments belonging to group DGROUP. Segments belonging to class STACK are used to define the size of the stack used for your application. Segments belonging to the classes BSS and STACK are last in the segment ordering, so that uninitialized data need not take space in the executable file.
In addition to these special segments, the following conventions are used by Watcom C/C++:
You can override the default naming convention used by Watcom C/C++ to name segments.