Solved

about DLL loading

Posted on 2001-07-19
14
259 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Syntax Check Delphi Seattle IOS app without MAC ? 1 97
Strange behavior when a form is closed 6 57
find a node in VST 2 68
Reconfigure Delphi Install? 2 51
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 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