Solved

about DLL loading

Posted on 2001-07-19
14
258 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 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

18 Experts available now in Live!

Get 1:1 Help Now