Why use DLL and not just a static library (LIB)?
I'm currently writing an engine, and I use a static link library, and I was wondering, why use DLL's?
why dont just use lib files? this way you dont need anything else but the exe...
I think there are two main reasons for this
1) You can change the DLL without having to rebuild the EXE. Useful if different people are working on different areas of your game.
2) Multiple programs can use the same DLL. This means the EXE can be smaller both on disk and in memory. For example the windows user32.dll DLL (which contains icons and user mode functions) could be statically linked into every windows program available but is rather memory inefficient.
Applying this to a game scenario, you could have a 3d engine in a DLL which your users download once. Then they could download different games which use this engine rather than having to keep downloading the engine for each game leading to smaller downloads for them.
1) You can change the DLL without having to rebuild the EXE. Useful if different people are working on different areas of your game.
2) Multiple programs can use the same DLL. This means the EXE can be smaller both on disk and in memory. For example the windows user32.dll DLL (which contains icons and user mode functions) could be statically linked into every windows program available but is rather memory inefficient.
Applying this to a game scenario, you could have a 3d engine in a DLL which your users download once. Then they could download different games which use this engine rather than having to keep downloading the engine for each game leading to smaller downloads for them.
a. imagine if you have a library contains 1 million functions,and you only need 1 of them.if you use static one all of 1 million functions will be included into your exe in compilation.but dll will setup the link. and the library will be called only when it is needed in run-time.
b. dll can be reused.update can be carried out by simply replace the dll.
b. dll can be reused.update can be carried out by simply replace the dll.
You can release newer versions of one DLL without having to replace the entire program. For one EXE this may not be a big hassle, but imagine if there was a major bug in the MSVCRT library. You would virtually have to update every program on your entire hard drive if you were using static libraries.
Quote:Original post by jimywang
a. imagine if you have a library contains 1 million functions,and you only need 1 of them.if you use static one all of 1 million functions will be included into your exe in compilation.but dll will setup the link. and the library will be called only when it is needed in run-time.
b. dll can be reused.update can be carried out by simply replace the dll.
Most linkers will only include code that is used into the output file.
You can also dynamically load dll's (even If you don't know which ones you need in advance) which is really handy. Supporting both opengl and directx for rendering is often done this way.
Another reasons is resource management. Dynamic DLL linking allows a process to only allocate address spaces for the DLL if and when needed.
Kuphryn
Kuphryn
Quote:Original post by smrAll linkers will remove unused code. In this case, all (exported) functions must remain in the DLL to be called from the executable, but with static linking only the function(s) used will be included in the executable. Thus, the DLL+EXE pair could be much larger than the static-linked EXE.Quote:Original post by jimywang
a. imagine if you have a library contains 1 million functions,and you only need 1 of them.if you use static one all of 1 million functions will be included into your exe in compilation.but dll will setup the link. and the library will be called only when it is needed in run-time.
b. dll can be reused.update can be carried out by simply replace the dll.
Most linkers will only include code that is used into the output file.
Like everything else, DLLs and static libraries have trade-offs that need to be considered. There is no silver bullet.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement