When to Use Shared Libraries

distributionlibraries

Note: I'm not sure if this question is more suitable for Stack Overflow or Programmers. The thought process behind putting it here was that it doesn't actually relate to coding itself.

I noticed a small freeware utility I have on my computer uses a couple of DLLs. From their names ("RenderAllChunks" and "RenderSlice"), it looks like they're being used just for specific functions. If outsourcing program-specific functions is really necessary, wouldn't it be better to just stuff them in a separate header file? It seems quite pointless to go through all the trouble of compiling, linking and distributing DLLs just for one function.

  • Is it bad to use shared libraries for small projects?
  • When/why are shared libraries preferable over static libraries (or even header files)?

Best Answer

Dynamic libraries are good for drivers, because they use a standardized interface where the OS can hook right into the code and not bother with command line arguments and crazyness if it were an application instead. For the same reason they're good for providing a common functionality to any program that wants to use it, such as Windows API DLLs. Dynamic libraries should never be created for a single app, with the possible exception of plug-ins.

I personally dislike static libraries. Since they're always loaded, they're taking up memory whether you're using them or not. I suppose they're useful if you're using someone else's library and constantly making use of it in your code.