C++ Library Loading
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: C++ Library Loading

  1. #1
    Join Date
    Jul 2011
    Posts
    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.

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,634

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

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,988

    Re: C++ Library Loading

    Quote Originally Posted by mikenac View Post
    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

  4. #4
    Join Date
    Jul 2011
    Posts
    1

    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.

  5. #5
    Join Date
    Apr 2010
    Posts
    20

    Re: C++ Library Loading

    Quote Originally Posted by whishtfar View Post
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center