Skip to content
UoL CS Notes

Dynamic Loading

COMP124 Lectures

This makes memory usage more efficient by only loading what part of a program is needed at any time.

The program image could consist of the following parts:

  • Main program
  • Different routines, classes
  • Error routines

Dynamic loading allows only parts of the image to be loaded, as necessary.

When a routine calls another routine, it checks to see if it has been loaded.

  • If not the relocatable linking loader is called.

This gives the advantage that unused routines are never loaded.

Linking

Linking is the integration of user code with system or 3$^{rd}$ party libraries.

  • Typically done directly after the compilation process.

Static Linking

Copies of the libraries are included in the final binary program image:

  • Can result in large images due to inclusion of many libraries.
    • These libraries may link to more libraries.
  • Wasteful both in terms of disc storage and main memory.
  • Can be managed by dynamic loading, but shared libraries are still repeated in memory multiple times.

Dynamic Linking

A stub is included in the image for each library routine this indicates how to:

  • Locate a memory resident library routine:
    • If already loaded.
  • Load the library:
    • If not loaded.

Allows re-entrant code to be shared between processes:

  • Supports library updates (including versioning).

    Libraries are not automatically updated when using static linking.

  • Keeps disc images small.

This requires some assistance from the OS as lower level memory organisation is necessary.

Memory Organisation

To help solve some of the software problems arising from the linear store, more complex memory models are used which organise the store hierarchically:

  • Segmentation
    • Subdivision of the address space into logically separate regions.
  • Paging
    • Physical subdivision of the address space for memory management.