Like any MS-DOS application, a Windows application can contain one or more code segments and one or more data segments, depending on the memory model you select when compiling the source-code modules of your application. For information about the memory-model options that are available to you, see Chapter 16, “More Memory Management.”
The memory model you choose will affect how efficiently your application will run with the Windows operating system. In most cases, the best model is the mixed model. When using the mixed model, you compile your modules to have default small- or medium-model settings and to name the data segments. You then override these default settings by using explicit FAR calls (in coded segments with the small-model settings) to call functions in other segments, or by using explicit NEAR calls (in segments with the medium-model settings) to call functions in the same segment. The mixed model has the following advantages:
Near calls reduce the amount of code generated by the compiler and make the functions execute more quickly.
Compiling the modules by using named code segments partitions the code segments into smaller segments, which are easier for Windows to manage as it moves the code segments in memory.
To create an application by using the mixed model (with the small-model default settings), follow these steps:
1.Provide prototypes for all functions in your source code that are called from outside the code segment that defines them. For the sake of convenience, you can place these prototypes in a header (.H) file. You must provide prototypes for all function calls made by one code segment to another as far calls using the FAR keyword. Following is an example of a function prototype for a far call:
int FAR MyCalculation(int, int);
2.Compile your C modules by using the /AS option to create the application that will use the small memory model.
3.Compile your C modules by using the /NT option to name the code segments of your application.
For more information about these and other compiler options, see Microsoft Windows Programming Tools.
Creating an application by using the mixed model with medium-model default settings is similar to this procedure, except for two differences: You would explicitly declare as NEAR those functions that are called only within the data segment that defines them, and you should compile the modules by using the /AM option to produce the medium-model default settings.