Shared library

From OSDev Wiki
Jump to: navigation, search

This article is a stub! This page or section is a stub. You can help the wiki by accurately contributing to it.

A shared library is a file which is shared between executables.

Usefulness

Some programs may contain identical parts. In the case of a static library, these parts have their own copy in each executable and program size is immense. This means it uses more memory and more disk space. In the case of a shared library, these parts are in a central file, all those unnecessary copies are eliminated and only one is kept. This approach uses less disk space and less memory. This is a bit similar to system calls located only in the kernel file, but used by all other executables. Shared libraries, as all libraries, can contain functions, structures, configuration data and values.

At least, that's the idea. In practice, systems with shared libraries may use more memory and/or disk space. When an OS has demand paging, (loading parts of files on demand,) shared libraries may in some cases use more memory than static. Programs using shared libraries and shared libraries themselves must be re-linked at load time. This means the in-memory copy is not the same as the on-disk copy, and so demand paging cannot be used in the same way. The relinked code could be paged out to swap files, (using more disk space!) but first it has to all be loaded for re-linking. This contrasts to a statically-linked executable, of which only the parts which are used need be loaded. For instance, bash contains code for command-line editing. This code is not used when running scripts, but for every script run, the editing code must be loaded and linked against the readline library.

Implementation

TODO

Personal tools
Namespaces
Variants
Actions
Navigation
About
Toolbox