16.6.2 Using Multiple Code Segments

Most Windows applications should be compiled by using the mixed memory model. The code should be partitioned into relatively small segments (8K or less). This allows Windows to move the code segments fluidly in memory. For more information about the mixed model, see Section 16.3, “Using Memory Models.”

When you compile a C module, the code segment is assigned the name _TEXT by default. You can assign the code segment a different name, using the /NT option of CL. You partition the code by assigning different names to the code segments for different modules. The following command line produces a code segment named CODESEG1:

cl /u /c /AS /Gsw /Oas /Zpe /NT CODESEG1 module1.c

You can assign attributes in the application's .DEF file that override the values you specified for the default CODE. For example, the following .DEF file excerpt declares all code segments to be movable except the code segment named CODESEG1, which is discardable:

CODE LOADONCALL MOVEABLE

        SEGMENTS
                CODESEG1 MOVEABLE DISCARDABLE