PMzone logo

Book cover

Project Guides


Component Libraries

Good programming languages are generally concise. This means they include only the basic constructs to make programs work. To expand the functionality of the language, component libraries are created. A component library is a collection of program routines and definitions that can be reused in many applications.

Most programming languages include some form of static or Dynamic Link Library (DLL). Typical libraries include text, numeric, and file input/output definitions; and contain extensive math, text, sound, video, and system type functions. Well-designed component libraries are reliable and efficient, and come with great documentation. They also are simple to implement.

Windows API

The Windows Application Programming Interface (API) is a set of definitions and functions specific to the Windows operating system. Some of the more important standard DLL files include: kernel32.dll, user32.dll, and gdi32.dll. Notice that the wow64 directory contains 32-bit calls to Windows functions while the system32 directory contains 64-bit calls. This can be misleading to novice programmers new to 64-bit Windows programming.

Standard C Library

The C programming language contains its own API, referred to as the Standard C Library. The library is declared in a number of header files that contain one or more macros, type definitions, and functions for routines such as string handling, mathematical computations, input/output processing, memory management, and several other operating system service sand macros.

certificate

Structured Program Libraries

Project 6: Learn How to Write a Library of Reusable Components

This project introduces users to structured program libraries. Reusable program libraries are designed to keep a core programming language as small as possible by allowing extensive capabilities to be added on through the use of such libraries. Excerpts in the accompanying project guides are taken from the book, Structured Program Libraries, Volume 1, First Edition.

Introduction

Ada is intentionally designed with a reduced set of reserved words. This minimizes complexity, compiler workload, and user learning curve. However, Ada is a modularly expressive and extensible language. It uses static and dynamic libraries containing packages that tap into powerful Win API and C Runtime functions to add functionality. This project is all about building support libraries to enhance and extend the capabilities of both the compiler and the Adagé programming language.

Structured Program Libraries

A library is a file containing a set of one or more combinations of definitions (configuration data), documentation, help data, variables and type specifications, pre-written code and functions, and classes that perform common tasks and can be included in an application's source code during the linking phase of program development. Libraries can be designed to be all-inclusive, that is, they can contain many components (symbols) similar to the C standard library. They also can be designed to contain only one function so that only that function is included during the linking process. In this manner, a compiler can have any number of external support libraries and include only those that are needed by a particular program.

Structured libraries are indexed so it is easy to find various components, called symbols (functions, variables, and so forth), contained in them. For this reason, linking a program whose components are ordered is faster than linking a program whose components are separate. Also, library code is generally organized in such a way that it can be used by multiple programs that have no connection to each other, while code that is part of a program is organized to be used only within that one program. As a result, the value of structured libraries lies in their organization for the purposes of being reused by other libraries and executable files.

Types of Libraries

There are basically two kinds of libraries that concern us: static and dynamic. Static libraries are created by a static linking process that copies parts of a static library into the actual executable program. Dynamic libraries, on the other hand, are created by dynamically linking only the references to memory locations of various components included in the dynamic library. Actual dynamic library code is not copied into the executable program. All references to components in a dynamic library are resolved during the linking process rather than each time the executable is run.

Static Libraries

Static libraries consist of a collection of routines, external functions and variables, and definitions that are added (inserted) into a program during the linking phase to create a stand-alone executable program. Static linking is often referred to as early binding. Once included in the program, the separate library file is no longer relevant during runtime. Static libraries are only used during the linking process and are not required when the application is run. In Windows, static files generally end with the .lib file extension.

The main advantages of static libraries are fivefold. First, since the parts of static libraries are included directly within the executable file itself, no separate libraries have to be loaded during program execution. Second, the application containing static file code can be certain that all its libraries are present and that they are the correct version. This avoids dependency issues from arising during compilation and execution. Third, static linking allows applications to be contained in a single executable file, simplifying application distribution and installation. Fourth, certain programs tend to run slightly faster with statically linked code. Fifth, only the components of a static library actually used by an executable have to be included in the executable file.

Conversely, static libraries have certain disadvantages. They increase the size of executable files since the code contained in static libraries is copied into the source code of each executable file that links with the static library to form a separate independent executable program. This also applies to static libraries that are merged with other static libraries. Additionally, when changes are made to static libraries, every program that links with the library must be rebuilt.

Dynamic Libraries

Dynamic (shared) libraries are linked to a program in two stages. First, when a program is compiled, the linker verifies that all the components (functions, variables, and definitions) identified in the program are present in the linked file. Note that dynamic library code is not inserted into the program's source code nor does it become part of the executable file. Instead, when the program is run, Windows checks out which shared libraries are linked to the executable program file, loads them into memory if they are not already there, and attaches them to the running program. This is referred to as late binding. In Windows, shared files generally end with the .dll suffix.

The advantages of Dynamic Link Libraries (DLL) include the following:

However, it takes slightly longer for programs that share DLL files to load because the DLL file must be loaded into memory and certain tasks performed by a program called a dynamic loader, which is part of the Windows operating system. Notice that DLL files are very similar to executable files, that is, Portable Executable (PE) for 32-bit and 64-bit Windows, but can not be run on their own without being invoked by an executable program. Like executable files, DLL files can contain code, data, and resources, in any combination. Importantly, DLL files execute in the same memory space as the executable program that calls it.

Ada Component Libraries

Most compiled languages have a standard library or set of component libraries to extend the capabilities of the core language or implement substantial portions of the language's functionality. Such libraries provide uniform services required by modern applications. As such, much of the code used by modern programming languages is provided in these component libraries.

Since Ada is deliberately designed with a reduced set of syntax constructs, it relies on a number of component libraries to increase its capabilities. Specific areas include system-level functions such as multi-core utilization and concurrency, use of the MMX and SIMD registers, memory organization, bit manipulation, and input/output services for a range of variable types and sizes. The Ada compiler uses a feature called smart linking to integrate how and when component library resources need to be used. This approach maintains the small size of resulting executable files as well as reduced memory usage.

Structured Program Libraries focuses on the creation of support libraries for the Ada programming language. However, the techniques covered in this book are applicable to most imperative programming languages.

NOTICE More discussion to come as the Structured Program Libraries project progresses.

Page Top

© 1997-2017 Transtar Management Services, Inc. All rights reserved. Terms of Use