 | | One of the most important uses for memory-mapped files is in the implementation of dynamically loadable shared libraries. In the old days, when a program was linked, all the executable code for the library routines it called (the code for the routines described in this book) was copied into the executable file. This consumed a lot of disk space and also took up a lot of memory, because there might be multiple copies of a routine (for example, printf) in memory at any given time. The introduction of dynamically loaded, shared libraries has solved both of these problems. Because the library is dynamically loaded, it does not have to be compiled into each program. Rather, when the program is executed, the system loads the library into memory and allows the program to transfer control to this area of memory. This conserves disk space by having only one copy of each library routine on the disk. Because the library is shared, each program that uses the library is using the same copy. Thus, there is only one copy of printf in memory at a time, and all programs that need it use the same copy. | |
|