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.
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
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.
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.
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.
Bookmarks