why make DLL's?

Started by
3 comments, last by Oldstench 16 years, 11 months ago
Im just wondering What is the purpose of having DLL's? It seems that it just creates more separation of your code.
Advertisement
And separation is a bad thing, you mean?

They allow you to, for example, separate code. Just like you say. Preferably you should separate code into pieces that doesn't logically belong together. By sticking it into dynamic libraries, you can provide new library files to upgrade parts of your product without the need to redistribute the entire application.

Plugins for your application example. Provide new plugins, or allow the user to select what plugins are needed, by just placing new library files into some plugin folder. Got an updated plugin? Just replace the old file. Why redistribute the entire application for an updated plugin.

Put file loading capabilities in your game engine into a dyanmic library for example. Got new file formats you want to load? Why redistribute your entire engine when you can just provide a new library file the user replace.

Got several applications sharing some independent code? Why have each application embed their own copy when you can put them in dyanmic library, so each application only need a single common copy. Need to upgrade the code? Replace the library file instead of redistributing all applications.

I'm sure there are better examples, but that's the point at least. They provide separation of code.
One of the original ideas of making DLLs was that code could be shared among applications. That way, executables need not to each have a copy of, say, the DirectX-library, but they could all share the code by using the DirectX DLL. Sadly, because so many versions of the same DLLs exist, nowadays many application put their own DLLs in the same directory, defeating the purpose.

Another use of DLLs is that you can build a new DLL and have it work with an application, without the need of recompiling the application.

IMHO much handier is the fact that you can select the DLLs to load during program execution. So, if your game comes with an editor built-in, you can make sure the editor code only gets loaded when it's actually used, freeing memory for normal play. Another use might be DLLs for different languages, so when the user is playing in Spanish, you can just remove the English strings from memory.

A last use is plugins. Many programs like Matlab, 3D Studio Max allow you to write extensions to the program. Since you do not have the source code to the programs (too bad..), you cannot edit the program and recompile. But, those developers defined an interface that you can use to build your own DLL. You can then put it in the application directory, and have the application call your code.
Quote:Original post by Brother Bob
And separation is a bad thing, you mean?


i never meant that it was bad. I never really thought of all those examples. I guess that right now as a beggining programmer im still thinking kind of small.
Quote:jchmack wrote:
I guess that right now as a beggining programmer im still thinking kind of small.


"Thinking small" while learning programming is really the only way that you will be able to digest and learn what can be an incredibly daunting exercise if frustration and early hair-loss.

You start out, you learn control structures and variable types - then arrays, pointers, and reference variables get thrown at you. Then you start hearing about these strange animals called vectors, and then the whole STL drops from above. Next thing you know you are in the middle of a full blown holy war as to what widget library to use and you still don't really understand why you keep getting memory leaks do to poorly implemented class destructors.

But the first time you crack that really difficult to grok recursion problem makes it all worthwhile.

This topic is closed to new replies.

Advertisement