Jump to content
  • Advertisement
Sign in to follow this  
Ilankt

Why use DLL and not just a static library (LIB)?

This topic is 5401 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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...

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Another reasons is resource management. Dynamic DLL linking allows a process to only allocate address spaces for the DLL if and when needed.

Kuphryn

Share this post


Link to post
Share on other sites
Quote:
Original post by smr
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.
All 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.

Like everything else, DLLs and static libraries have trade-offs that need to be considered. There is no silver bullet.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!