Skip to main content
gamedev.net
🔒 Locked

Librarys

Started by brwarner Jan 25, 2006 at 8:01 PM 1 replies 400+ views
Original Post
brwarner
brwarner
Hi, What is the diffrence between static (.lib) and dynamic(.dll) libraries and when should i choose which??
ciroknight
ciroknight
A static library (.lib on Windows) is a library that is linked to the program in a static fashion; when the program is loaded, so is the library. The advantage of this is that you will certainly get the version of the library that you want, and that no APIs will have been changed to break your software. The disadvantage of this is that you will definitely get the version of the library that you want: if an update has occured, you'll still have the old version linked.

A Dynamic Library (.dll on Windows) is a library that is conditionally loaded at runtime; if the library is already in memory, it doesn't need to load it again. The advantage of this is that you're likely to only have one copy of the library in memory, and that is much faster than loading 5-10 version if your program's library is used by a lot of applications. The disadvantage of this is, that if something breaks API stability inside of this DLL, and it needs to be updated, then you're screwed; the API call will be made improperly, and your program will die a hard death.

So it's really up to what you're implementing. If it's a Window Manager, or a Web Browser or something, you're going to want to use DLLs where you can; these libraries are going to be needed by other programs. If your game needs a library that's very specific to its needs (such as your creature manager or something), you might consider going with a statically linked library, or just build the code into the application to begin with.

That's the skinny of it. Object Oriented programming brought on a lot more uses for dynamic linking (code polymorphism, inheiritance, etc), but the fundamental tennants are all you really need to know to make the decision.
erissian
erissian
Absolutely.

If you think you will have multiple copies of a program running at one time, then dll is the way to go. It loads once and is shared by all the instances of your program.

Static libraries load once for every copy of your program. If you are only running one or two instances at a time, then these can be more reliable and cost less in overhead.
We''re sorry, but you don''t have the clearance to read this post. Please exit your browser at this time. (Code 23)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.