Solved

about DLL loading

Posted on 2001-07-19
14
256 Views
Last Modified: 2010-04-06
2 programs are using the same DLL.

Question 1 is :
It there are both launched, how many times the DLL is loaded in memory ? once or twice ?

Question2 is :
If One program is loaded twice. how many times the DLL is loaded in memory ? once or twice ?

regards.
Mike
0
Comment
Question by:gklux
  • 3
  • 3
  • 3
  • +3
14 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 6297449
DLL is loaded each time LoadLibrary() is called.
ziolko.
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 100 total points
ID: 6297459
0
 

Expert Comment

by:article
ID: 6297477
The DLL will be loaded only once.  That's why one use DLL to share common codes.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6297487
:o/
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6297495
as far as i know a dll is allways loaded once, and multiple loads are counted by an referncecounter.

only the memory for vars/structures is
allocated additional for each processwell, i'm not an expert of this,
therefore i may wrong

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6297500
:o/
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6297846
Epsylon's link should explain it all in detail, but in case you're too lazy to read all that stuff, here the answer in short:

"article"'s answer is wrong. Each process loads its own copies of each needed dll. A prove is simple: You can change segments of a dll in the memory context of your own process - and this "patching" shows only effect in the current process. Several API hooking methods are using this effect, e.g. ImportTablePatching works only process wide.

However, there are some exceptions to what I said above:

(1) In win9x based systems there is a shared area ($80000000 - $FFFFFFFF) and a non-shared area ($00000000 - $7FFFFFFFF). The non-shared area is private to each process. Dlls loaded there are also private to each process. Dlls that are loaded in the shared area (some system dlls) are shared among all processes. Those dlls are only loaded once for all processes. In winNT based systems the whole memory area is private, there is no shared area, thus no shared dlls, either.
(2) If some segments of a dll are marked as being shared, these segments are mapped into all processes by Windows.
(3) To boost up the overall speed, Windows internally does a lot of tricks to avoid double loading of dlls system wide. But that's burried in the deepest OS regions and hidden very well. Technics like CopyOnWrite and such stuff help realizing this. But at application level it is really this way, that each process has its own copy of all (non-shared) dlls.

Regards, Madshi.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 27

Expert Comment

by:kretzschmar
ID: 6297903
as i said, i'm not an expert for this :-)
0
 
LVL 21

Expert Comment

by:ziolko
ID: 6300964
Epsylon's comment confirms what I said earlier: each time LoadLibrary() is called.
ziolko.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6301264
Hi ziolko,

if the same process calls LoadLibrary twice, the dll is only loaded once and a reference count is incremented. Furthermore dlls are also loaded if they're statically linked to by another module, without that anyone calls LoadLibrary.

Regards, Madshi.
0
 

Author Comment

by:gklux
ID: 6301939
Hi all, and thanks for such lot answers.

I Think that Epsylon's answer is the best one.

best regards.

Mike
0
 

Author Comment

by:gklux
ID: 6301941
thanks and regards
Mike
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6302102
thank you too, Mike
0
 
LVL 21

Expert Comment

by:ziolko
ID: 6305340
Madshi thx I didn't know that.
ziolko.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now