Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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)?
share|improve this question
2  
Here is the right place, SO is just for specific programming questions. –  user1842 Dec 16 '10 at 21:55
1  
We should probably generalize this to shared vs static libraries. –  alternative Dec 16 '10 at 23:03
    
@mathepic Done. –  Maxpm Dec 16 '10 at 23:07
add comment

3 Answers

up vote 5 down vote accepted

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.

share|improve this answer
1  
+1 for the exception of plugins –  Mason Wheeler Dec 16 '10 at 22:35
1  
+1 for plugins; I think this leads to a useful distinction between compile-time linking against a library and dynamic loading with dlopen or LoadLibrary, which is not possible with static libraries. –  alternative Dec 16 '10 at 23:05
add comment

My rule is if it is a logical chunk of code that can perform a function or groups of functions that has a possibility of reuse it should be in a dll. dll Should not contain only one function or functions that can only work dependent on other functions in another dll.

share|improve this answer
    
So you're saying it's about making sure the DLL isn't too localized? –  Maxpm Dec 16 '10 at 21:37
add comment

Particularly if you work in commercial/mass market software, its best to limit the number of external dependencies. In my software, I only use a library when I cant compile it directly into an executable (for example, calling a c-made DLL from a Delphi program). Limiting the number of dependencies limits the number possible problems relating to them during deployment to machines whose environment you dont control.

Years ago when hard drives were small and expensive there might have been some use for using DLLs to cut down on disk space, but that age is long gone on PCs, imo. And probably even on phones and most devices these days.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.