Are .dll files loaded once for every program or once for all programs?(.dll 文件是为每个程序加载一次还是为所有程序加载一次?)
问题描述
我有一个简单的小问题,知道的人可以轻松回答,我用谷歌搜索但找不到答案.
I have a simple small question which someone who knows will be able to answer easily, I searched google but couldn't find the answer.
计算机上同时运行着许多程序,我的问题是:当一个程序加载一个 DLL 时,它是实际加载了 DLL 文件还是找到了已加载 DLL 的内存?例如,ws2_32.dll (winsock 2) 是为每个使用winsock 的程序加载,还是加载一次并且所有使用它的程序都使用相同的内存地址来调用函数?
There are many programs running at once on a computer, and my question is: when a program loads a DLL, does it actually load the DLL file or does it find the memory in which the DLL is already loaded? For example, is ws2_32.dll (winsock 2) loaded for every program that uses winsock, or is it loaded once and all programs that use it use the same memory addresses to call the functions?
推荐答案
它加载一次,所有程序共享相同的内存中代码副本.这有点复杂,但对于 DLL 的只读部分(即代码),操作系统加载程序使用一种称为内存映射"的技术将 DLL 映射到进程的地址空间.这些页面只被所有进程加载到物理内存中一次,即使它们可能将页面映射到其虚拟地址空间中的不同地址.
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.
这篇关于.dll 文件是为每个程序加载一次还是为所有程序加载一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:.dll 文件是为每个程序加载一次还是为所有程序加载一次?
基础教程推荐
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01