128 Chapter 5
Creating and Using Libraries
Example Program Comparing Shared and Archive Libraries
Example Program Comparing Shared
and Archive Libraries
As an example, suppose two separate programs, prog1 and prog2, use
shared libc routines heavily. Suppose that the a.out portion of prog1
is 256Kb in size, while the prog2 a.out portion is 128Kb. Assume also
that the shared libc is 512Kb in size. Figure 5-2 shows how physical
memory might look when both processes run simultaneously. Notice that
one copy of libc is shared by both processes. The total memory
requirement for these two processes running simultaneously is 896Kb
(256Kb + 128Kb + 512Kb).
Figure 5-2 Two Processes Sharing libc
Compare this with the memory requirements if prog1 and prog2 had
been linked with the archive version of libc. As shown in Figure 5-3,
1428Kb of memory are required (768Kb + 640Kb). The numbers in this
example are made up, but it is true in general that shared libraries
reduce memory requirements.