Overlay (programming)


In a general computing sense, overlaying means "the process of transferring a block of program code or other data into main memory, replacing what is already stored". Overlaying is a programming method that allows programs to be larger than the computer's main memory. An embedded system would normally use overlays because of the limitation of physical memory, which is internal memory for a system-on-chip, and the lack of virtual memory facilities.

Usage

Constructing an overlay program involves manually dividing a program into self-contained object code blocks called overlays or links, generally laid out in a tree structure. Sibling segments, those at the same depth level, share the same memory, called overlay region or destination region. An overlay manager, either part of the operating system or part of the overlay program, loads the required overlay from external memory into its destination region when it is needed; this may be automatic or via explicit code. Often linkers provide support for overlays.

Example

The following example shows the control statements that instruct the OS/360 Linkage Editor to link an overlay program containing a single region, indented to show structure :

INCLUDE SYSLIB
INCLUDE SYSLIB
OVERLAY A
INCLUDE SYSLIB
OVERLAY AA
INCLUDE SYSLIB
INCLUDE SYSLIB
OVERLAY AB
INCLUDE SYSLIB
OVERLAY B
INCLUDE SYSLIB


+--------------+
| Root Segment |
| MOD1, MOD2 |
+--------------+
|
+----------+----------+
| |
+-------------+ +-------------+
| Overlay A | | Overlay B |
| MOD3 | | MOD7 |
+-------------+ +-------------+
|
+--------+--------+
| |
+-------------+ +-------------+
| Overlay AA | | Overlay AB |
| MOD4, MOD5 | | MOD6 |
+-------------+ +-------------+

These statements define a tree consisting of the permanently resident segment, called the root, and two overlays A and B which will be loaded following the end of MOD2. Overlay A itself consists of two overlay segments, AA, and AB. At execution time overlays A and B will both utilize the same memory locations; AA and AB will both utilize the same locations following the end of MOD3.
All the segments between the root and a given overlay segment are called a path.

Applications

, most business applications are intended to run on platforms with virtual memory. A developer on such a platform can design a program as if the memory constraint does not exist unless the program's working set exceeds the available physical memory. Most importantly, the architect can focus on the problem being solved without the added design difficulty of forcing the processing into steps constrained by the overlay size. Thus, the designer can use higher-level programming languages that do not allow the programmer much control over size. On the other hand, failure to consider interactions between program modules might lead to thrashing and a significant performance penalty.
Still, overlays remain useful in embedded systems. Some low-cost processors used in embedded systems do not provide a memory management unit. In addition many embedded systems are real-time systems and overlays provide more determinate response-time than paging. For example, the Space Shuttle Primary Avionics System Software uses programmed overlays.
Even on platforms with virtual memory, software components such as codecs may be decoupled to the point where they can be loaded in and out as needed.

Historical use

IBM introduced the concept of a chain job
in FORTRAN II. The program had to explicitly call the CHAIN subroutine to load a new link,
and the new link replaced all of the old link's storage except for the Fortran COMMON area.
IBM introduced more general overlay handling in IBSYS/IBJOB, including a tree structure and automatic loading of links as part of CALL processing.
In OS/360, IBM extended the overlay facility of IBM 7090/94 IBSYS IBLDR by allowing an overlay program to have independent overlay regions, each with its own overlay tree. Another dynamic system of overlays could be constructed using the LOAD or LINK system macros. Separately-compiled modules were loaded anywhere in available memory and retained until a DELETE macro was issued for them. Loaded programs could, in turn, load other programs and so on. OS/360 also had a simpler overlay system for transient operating system SVC routines, using 1024-byte SVC transient areas.
Systems using Memory segmentation typically do not require overlay facilities.
Programs on Burroughs Large Systems are composed of segments, which are natural divisions of the program such as COBOL paragraphs, ALGOL procedures, data structures, etc. Each segment is dynamically loaded as needed, and then possibly removed to swapped out to free storage. Specific overlay structures are not necessary because the MCP overlays automatically. Multics, likewise, does not require specific overlays, because each module is a separate segment, which the supervisor loads, deletes, or swaps out as needed.
In the home computer era overlays were popular because the operating system and many of the computer systems it ran on lacked virtual memory and had very little RAM by current standards: the original IBM PC had between 16K and 64K, depending on configuration. Overlays were a popular technique in Commodore BASIC to load graphics screens.
"Several PC/MS-DOS linkers in the 1980s supported in a form nearly identical to that used 25 years earlier on mainframe computers." Binary files containing memory overlays had de facto standard extensions .OVL or .OVR. This file type was used among others by WordStar, dBase, and the Enable DOS office automation software package from Enable Software. Borland's Turbo Pascal and the GFA BASIC compiler were able to produce.OVL files.