12.7.1 Restrictions on Overlays

Not all programs can use overlays. You will probably need to reorganize the code to accommodate the limitations explained in this section. Even after reorganization, some programs might not be convertible to overlay form or might not show a significant reduction in the amount of memory needed to execute them.

Consider the following restrictions before trying to overlay a program:

You can use overlays only in programs with multiple code segments, because separate segment names are needed for overlays. Only code is overlaid, not data. The data becomes part of the “root” section of the program that is always in memory.

Only 255 overlays can be specified. The program can define only 255 logical segments (segments with different names). This limits the total size of an overlaid program to 16 megabytes.

Only one overlay (in addition to the root) can be in memory at any one time. You must structure your program accordingly.

Duplicate names for different overlays are not supported; each module can appear only once in a program.

You must use far call/return instructions to transfer control between overlaid files. You cannot overlay files containing near routines if other overlays call those routines.

You cannot jump out of or into overlaid files using the longjmp C-library function. You can, however, use long jumps within an overlaid file.

You cannot use a function pointer to call a routine out of or into overlaid files. You can, however, use a function pointer to call a routine within an overlaid file.

You cannot use the same public name in different overlays.

The code required to manage overlays adds about 2K to 3K to the size of the root module.

WARNING:

Never rename an executable program file containing overlays if it is to run under DOS 2.x and earlier. LINK records the .EXE filename in the program file. If you rename the file, the overlay manager may not be able to locate the proper file. You can rename an .EXE file that will run under DOS 3.x and later.