Are .dll files loaded once for every program or once for all programs?

我的梦境 提交于 2019-11-28 09:43:22

It's loaded once and all programs share the same in-memory copy of code. It's kind of complicated, but for the read-only sections of the DLL (that is, code) the operating system loader uses a technique called "memory mapping" to map the DLL into the process's address space. The pages are only loaded into physical memory once for all processes, even though they may have the page mapped to different address in their virtual address space.

However, each process has a separate data section (so that global variables are not shared - unless you explicitly ask them to be) and they obviously also have a separate heap so that dynamically-allocated memory is not shared.

It depends on what you mean by "loaded".

The DLL is prepared for shared use of code and data: most Windows environments honor the shareability (by mapping the same memory copy of the code into each process's memory space) to conserve memory.

However, part of the "load" operation (from a process's point of view) is running the DLL's initialization: that is done separately in each process with distinct copies of the data areas which are private to each process.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!