对于采用virtual address的操作系统来说,多个进程共享一份动态库的方法如下:
操作系统将公用的动态库加载到物理内存中,假设A,B两个进程都需要用到这些dll, 则只需将dll在物理内存中的地址 与 进程A B的虚拟地址空间做一个映射连接。
《Operation system concepts, 7th edition》中的解释比较直观了:
" System libraries can be shared by several processes throgh mapping of the shared object into a virtual address space. Although each process considers the shared libraries to be part of its virtual address space, the actual pages where the libraries reside in physical memory are shared by all the processes. Typically, a library is mapped read-only into the space of each process that is linked with it."
启动程序时, Loader会去查找该程序依赖的链接库,首先看该链接库是否被映射进内存中,如果没有则加载。