-
July 8th, 2011, 04:42 PM
#1
C++ Library Loading
I have lately been a little confused about the way that libraries are loaded in C++, specifically in Windows. I understand the whole search process, but can anyone answer this:
If I have NotePod.exe, which will load Foo.dll, and I have FooPod.exe that will also load Foo.dll, will there be two instances of Foo.dll loaded into memory? If NotePod.exe loads Foo.dll, and then FooPod.exe starts, will it load Foo.dll from the already loaded (by NotePod.exe), or will it perform the normal search/load process?
Recently we have been having some issues that may be DLLHELL, and I would really like to know if this is true first.
Thanks for any response.
-
July 8th, 2011, 05:26 PM
#2
Re: C++ Library Loading
As far as I understand it any exe that loads a dll will do that according to the dll load rules (http://msdn.microsoft.com/en-us/libr...(v=VS.85).aspx) and it will not be a copy of an already loaded one.
-
July 11th, 2011, 05:35 AM
#3
Re: C++ Library Loading
Originally Posted by mikenac
If I have NotePod.exe, which will load Foo.dll, and I have FooPod.exe that will also load Foo.dll, will there be two instances of Foo.dll loaded into memory?
There will be one dll instance loaded into NotePod.exe process address space, and one dll instance loaded into FooPod.exe address space. Both processes use virtual memory separate from each other. Nevertheless, Virtual Memory Manager (VMM) will load Foo.dll code sections to physical memory only once, if possible. Data sections of the dll will occupy the same physical memory until getting modified, then copy-on-write mechanism comes in effect producing separate physical memory page allocation. So, in a exe process virtual memory the Foo.dll will comprise of the same code sections and individual data sections, unless the processes have to load the dll from different locations.
If NotePod.exe loads Foo.dll, and then FooPod.exe starts, will it load Foo.dll from the already loaded (by NotePod.exe), or will it perform the normal search/load process?
The latter. Every process load performs standard load routine. But while loading dll the VMM decides whether to map already loaded sections to process virtual memory as they are, or create new physical allocation by loading individual dll version sections.
Last edited by Igor Vartanov; July 11th, 2011 at 05:40 AM.
Best regards,
Igor
-
July 29th, 2011, 10:40 AM
#4
Re: C++ Library Loading
As I understand, the dll with same name in same place of disk, windows load it once, it exist in system space, every process which use the dll share the same dll space.
-
July 29th, 2011, 02:15 PM
#5
Re: C++ Library Loading
Originally Posted by whishtfar
As I understand, the dll with same name in same place of disk, windows load it once, it exist in system space, every process which use the dll share the same dll space.
No, this is wrong. The *.dll has to be loaded once into every process address space. It is loaded only once if the *.exe and any amount of *.dlls used by the *.exe use the same *.dll. That's loading a *.dll once into a process address space.
You cannot load one copy for every application that loads the *.dll - you have to deal with global variables that would be stomped on by every application that loads the *.dll. That would include static variables within functions.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|