Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Do you use .dll's in your game vs .lib?

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Do you use .dll's in your game vs .lib?
lin lin
Member #7,251
May 2006

I can't seem to grasp the concept for these two. Can they even be compared?

A .lib uses static linking and there is no need to include the .lib files for the end user right?

As oppose to a .dll which uses external linking and is a required file for the end-user to run your program.

Are they the same aside from these 2 differences? Both of them provide functions and resourcesfor your game. I suppose .DLL's would be useful as a resource if you were make updates to your game, instead of making the user re-download the entire updated game, you can just have them download and replace the old .dll file?

Would that work? Can you load resources into .lib or .dll fles? Resources such as Bitmaps or Midi files? I would be nice if the game was just a .exe and a .dll for all the resources.

I am developing my game, all my functions are in header files and all resources are saved externally. Would like to put some of the resources in .dll's or .lib's. I can't ignore these 2 file types forever... Gotta learn em.

Thanks in advance.

jmasterx
Member #11,410
October 2009

You can load resources from a DLL, but it's not exactly trivial and since you need an rc file it sort of makes it Windows Only.

You could always rename a zip file to dll and use physfs to open it :p

torhu
Member #2,727
September 2002
avatar

Using a DLL just for resources is not very common, most games use some other file format for that. Other formats tend to be easier to use, and also cross-platform.

As for .lib files, IIRC you can't put resources in them (they are just a collection of .obj files). But you can put them in the .exe, as .exe files have the same format as DLLs. The process is described here. This is most commonly done with the main application icon, so that Windows Explorer, etc. will show it as the icon for the executable.

lin lin
Member #7,251
May 2006

What are .dll's used for? Storing methods for classes? Datatypes? I am getting the picture .dll's are for windows applications and is not meant for games...

.Libs are used more often. But isn't it the same thing? Just a bunch of methods, data types and classes for your game? I want to impliment one or both in my game. I am getting sick of putting all my function defintions and classes in header files.

Arthur Kalliokoski
Second in Command
February 2005
avatar

lin lin said:

What are .dll's used for? Storing methods for classes? Datatypes? I am getting the picture .dll's are for windows applications and is not meant for games...

You can store data in .dll's if you want, and they are sometimes used for games (allegro for windows creates alleg<version>.dll by default).

Quote:

.Libs are used more often. But isn't it the same thing? Just a bunch of methods, data types and classes for your game? I want to impliment one or both in my game. I am getting sick of putting all my function defintions and classes in header files.

A static library file is used at compile time to include the function binary code that your game needs right in the .exe. DLL files also need a "lib" file to export the DLL names of the functions, but your game only has those names/identifiers rather than the code. The DLL will have the code in that case, and your game will call those functions. If you make improvements to a game engine, you only need to provide a new DLL rather than an entire new exe. OTOH, calls to DLL's are somewhat slower (not a problem if function takes significant time itself) and DLL's tend to thrash the cache due to always being loaded on a 4096 byte boundary.

IMO, DLL's were mostly useful back in the days of 4 megabyte machines, since many programs can use one dll for various functions, and the dll only takes up memory once, rather than a big block of code in each exe.

They all watch too much MSNBC... they get ideas.

Vanneto
Member #8,643
May 2007

You are mixing things up. A .lib file is a file used at compile time. It can be statically linked in your program so that no DLL is needed or it can be a dynamic .lib file in which case when the program compiles it will need a corresponding .dll file to function.

Why are .dll files used? Well, for one thing, you could have a .dll that handles networking stuff. So when a bug arises in the networking code you would just have to give your users the updated .dll and they wouldn't have to download the whole game again.

Another thing is common dll files like kernel32.dll, user32.dll, etc. If it weren't for dynamic linking you would have to statically link all these DLLs in your program or ship them with your game adding unnecessary size to your game. But because these are dynamically linked at program startup and are available in every Windows installation you don't have to worry about them.

So, .lib files are used at compile time, .dll files are used at runtime. For more on .dll files, see the Wikipedia entry.

EDIT: beaten.

In capitalist America bank robs you.

jhetfield21
Member #12,379
November 2010

well if its the windows port of a game we are talking about many or most have them(dlls).
but it's not a rule.Sims 3 doesn't have any but GTA4 and Neverwinter Nights have them.

lin lin
Member #7,251
May 2006

What coding does a .dll store? Function definations? Methods? Classes? External data types?

Arthur Kalliokoski
Second in Command
February 2005
avatar

Using a search engine would be faster, easier and more convenient than asking here.

They all watch too much MSNBC... they get ideas.

Vanneto
Member #8,643
May 2007

Everything you mentioned can be in a dll. Allegro 4/5 is in a dll. A virus could be in a dll. Basically, a DLL is in the same format as an PE file (.EXE) so everything that can be in an .exe file can be in a .dll file.

Again, read the Wikipedia entry.

EDIT: beaten again

In capitalist America bank robs you.

torhu
Member #2,727
September 2002
avatar

lin lin, you shouldn't bother creating DLLs for your game. If there is a bug in your game code, just give your users a new .exe. And use .zip files or something for data. Or load the files directly from the original files.

lin lin
Member #7,251
May 2006

Thanks for the advice guys. One last question...

I've read some documents regarding .dll's and .lib files. It's just like building an exe except the output is a .dll or a .lib instead. I've seen people have function definations, declarations and methods in these lib files.

I've been doing the same thing except I've been using header files.

Headers:
#include "Function prototypes.h"
#include "Function definations.h"

Is it almost the same thing? Should I bother using .libs instead? Both .lib and .h are static linked. So I don't think there's any advantages as far as space is concerned.

Tell me if this may be a good idea:
I can use .dll for levels and items. When the time comes I can release a "demo" which has level.dll... As the demos expand I can add more .dll or keep updating the old one without having users re-download and re-install. My issue is does this have to be a .dll? I can design my own file type .lin and have the game look for this file the same way it'd look for using the previous method. .dll can be shared by all programs, but my program is the only one that'll be accessing it. So I imagine I can just create my own file type and do the "updates" for each demo instead of venturing into unknown grounds...

I do want to learn more about them though, I just can't think of a good use for them in game development. Allegro uses .dll's but allegro isn't a game is it? ;D

Thomas Fjellstrom
Member #476
June 2000
avatar

lin lin said:

Is it almost the same thing? Should i bother changing? Both .lib and .h are static linked.

Sorta. Only putting a lot of code in headers is bad.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Arthur Kalliokoski
Second in Command
February 2005
avatar

Header files are to define things. No executable code or instances of data should be in those. That's what the 'c' or 'cpp' extension is supposedly for.

DLL's allow you to break your exe up into separate files, not just one big chunk. One single DLL can be used by more than one exe. If you compile all the Allegro examples statically, each file will be several times the size of the ones that link to the DLL, since most examples only have a small amount of code compared to the size of the Allegro library.

They all watch too much MSNBC... they get ideas.

lin lin
Member #7,251
May 2006

Header files are to define things. No executable code or instances of data should be in those. That's what the 'c' or 'cpp' extension is supposedly for.

Very interesting, up till now I've been using header files and 1 .cpp file. I keep the function definations in one .h file and prototypes for them in another. My .cpp only has the main loop for the game with all the function calls directed towards header files.

It's been working fine so far I don't experience slow downs or breaks.

I had a feeling having all these headers was a bad idea...

Arthur Kalliokoski
Second in Command
February 2005
avatar

You can give them the txt extension if you want, but common practice is to not put code and actual instances of data into header files.

They all watch too much MSNBC... they get ideas.

Thomas Fjellstrom
Member #476
June 2000
avatar

lin lin said:

I had a feeling having all these headers was a bad idea...

Headers are fine, but putting code in headers is generally considered a bad idea[1].

References

  1. Not including inline functions and C++ template classes

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

lin lin
Member #7,251
May 2006

I see. Thanks for the help. I am looking up some tutorials on making simple .dll's for console first.

I am programming an FF Tactics clone. However, I don't want to release demos, instead it's better to release it in modules. For example, the first release will have world 1, second release some time later will add world 2.. etc.. etc.

.Dll's would be a good idea in this situation since I don't want users to keep re-installing every update. I'd just have them download and replace the old .dll's. I can't do this with .libs.

Just in my mind I don't see how a .dll is any different compared to me just making my own file type (.lin) and have the .exe look for this file instead. Sure it can't be shared like a .dll, but my program is the only thing that would be calling it anyway. Maybe your right... .dll's have outlived their usefulness years ago...

Thomas Fjellstrom
Member #476
June 2000
avatar

If levels need special code, releasing them in a dll would work. But I imagine that you won't need a bunch of special new code per level (maybe some levels..), so you can just release data files for the game to load.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

lin lin
Member #7,251
May 2006

Can you give me your opinion on what kind of files you guys prefer?

Do you make your own file types? Use .dlls? .libs? And what do you use them for?

Arthur Kalliokoski
Second in Command
February 2005
avatar

I make new data formats all the time, but I only use the object files produced by compilers and assemblers for code. I don't even bother stuffing them into a library.

They all watch too much MSNBC... they get ideas.

Trent Gamblin
Member #261
April 2000
avatar

I use physfs, which supports zip, directory, pak, etc. I don't yet know what I'm going to go with for my final release... I haven't decided yet if compressed or uncompressed will be better. On the one hand compressed files are smaller, but then the files load slower. It depends on whether or not our slowest target device can keep up while loading from a compressed archive or not.

Arthur Kalliokoski
Second in Command
February 2005
avatar

I'd vote for uncompressed (at least for PC) because disk space is so ginormous these days. Zipping up the whole thing for installation takes care of the bandwidth problem when downloading the files.

They all watch too much MSNBC... they get ideas.

Thomas Fjellstrom
Member #476
June 2000
avatar

Yeah, I'd think if loading was an issue, you could support both compressed and uncompressed, and on the slow devices, have it uncompress the data on install.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Trent Gamblin
Member #261
April 2000
avatar

Those are some options, but I'm still not decided and won't be until I do some testing further along. I already think we may have to drop what was our lowest target device, since loading the amount of graphics we load per level from flash on that device is terribly slow. So it might be 3rd gen iGadgets and above, as far as those devices go. No clue about android, and the others, it doesn't really matter because they're plenty fast either way.

 1   2 


Go to: