Solved

about DLL loading

Posted on 2001-07-19
14
262 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert GUI app into console app for Win32 Env 5 125
Dynamically Created Query 3 69
Delphi, TImage, Png 2 18
IP without any Dots 1 50
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

685 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