.dll文件是否为每个程序加载一次或为所有程序加载一次? [英] Are .dll files loaded once for every program or once for all programs?

查看:407
本文介绍了.dll文件是否为每个程序加载一次或为所有程序加载一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的小问题,知道的人会很容易回答,我搜索google但找不到答案。

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已经加载的内存?例如,是为使用winsock的每个程序加载ws2_32.dll(winsock 2),还是加载一次,并且所有使用它的程序使用相同的内存地址来调用函数?

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文件是否为每个程序加载一次或为所有程序加载一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆