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

Thread: Application linking

  1. #1
    Join Date
    Jun 2008
    Posts
    32

    Application linking

    Hi, I'm after a bit of help with regards to linking and the pros / cons of static vs dynamic linking.

    At present, We have a large application consisting of ~120 libs / dlls and a 20meg .exe file. Now, looking at most of the projects it seems we almost always build and link to dll's rather than to static libs. The linking is very rarely done at run-time though because almost all of it is used in the application so it all loads at startup.

    What is getting to me is that this is one application and we seem to have dll's that are exclusively loaded at startup, never on the fly, which is surely the advantage of dlls?

    Why aren't we just using libs? We would then presumably end up with a huge 150 meg .exe file which doesn't sound right to me...but why shouldn't we do it like that? It is one application and surely it'd be faster like that rather than loading 80+ of our own dll's on startup?

    I hope my terminology is correct here.

    I suppose ultimately my question is this. If you load dll's at startup ALL THE TIME, what is dynamic about that? Why not just use libs?

    Thanks for any help on this,

    Lewis

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,762

    Re: Application linking

    it is always smart to leave MFC and the VC runtime as DLL's. Because other programs not created by you could also be using them.
    If multiple exe's are having the SAME dll's loaded, then really, they code is shared among the various processes, and this tends to enhance performance.

    If you have dll's that are made by yourself, and which are only ever used by 1 exe, and they're always loaded, then that doesn't really offer much benefit. At best it gives you a means to provided patches to a user only by changing a single DLL rather than the whole lot.
    At the same time, by having multiple compilands and linkings, you're preventing the compiler/linker from aggressively weeding out any part that isn't being used.

    DLL's really only come into their own when multiple different processes are making use of them.
    Alternatively DLL's offer a means to speed up initial load and reduce memory consumption by delay loading, or by dynamic loading and unloading. But if you aren't makinguse of that, then it's another reason against using dll's.

  3. #3
    Join Date
    Jun 2008
    Posts
    32

    Re: Application linking

    Brilliant, thanks so much for the reply. It seems my thinking is correct from what you say. If we're not making use by delay loading and nothing else should be using our dll's (they shouldn't) then perhaps we should move to static libs.

    Is there a limit to exe size with this? I tried changing one of our dlls to a lib and the main exe that linked to it grew by <100k but this allowed me to delete a 3 Mb dll...

    The exe is around 20 Mb in debug but I think the release exe is more like 9 Mb...

    My worry is that if I chose to change lots of dll's to libs, then the exe could get really large 50-100 Mb which would cause issues I'd imagine.

  4. #4
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,632

    Re: Application linking

    The biggest impact when changing from dll's to static libs will probably be the time you have to spend waiting for the code to link. Also, like most of us you probably work at a place where the it-guys can't sleep at night due to their virus paranoia so the mandatory virus scanner is probably set to scan both on reads and on writes. That means that first are the libs scanned when created, then when the linker reads them and finally the exe is scanned when written. All summing up to making the build process a painful snail-paced experience...
    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

  5. #5
    Join Date
    Jun 2008
    Posts
    32

    Re: Application linking

    Yes, linking time does seem to be quite high, certainly when linking our exe.

    It begs the question of why don't we have two setups? In debug, we could build dll's which are always loaded at startup but allow easy code changes without relinking. in release we could perhaps see a performance increase by moving to static libs when we don't care about relinking times...

    I'm curious and might give it a go on a handful of our larger, more heavily used dll's.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center