Sign in to follow this  
Brice Lambson

DLL Look-Outs

Recommended Posts

Brice Lambson    164
It's me again -- the kid that plunges in the deep end without knowing how to swim well enough. So, I split my Engine (2D via SDL) into Dynamicly Linked Libraries: Kernel.dll (imports SDL, SDL_image) Network.dll (imports Kernel, SDL_net) Audio.dll (imports SDL, SDL_mixer, Kernel) GUI.dll (imports SDL, SDL_image, Kernel) Script.dll (imports SDL, SDL_image, SDL_mixer, SDL_net, Kernel, Network, Audio, GUI) Engine.exe (imports SDL, SDL_image, SDL_mixer, SDL_net, Kernel, Network, Audio, GUI, Script) ...but now only half the data files load, and the graphics, that are drawn per-pixle by the code, are discolored. What might be the problem here? Or in other words: What are some things that I should look out for when using DLLs? Thanks. -Brice

Share this post


Link to post
Share on other sites
JTippetts    12969
The biggest problem to look out for, in my experience, is using DLLs needlessly. Dynamic libraries serve a purpose, and that purpose is mostly to prevent identical code from being loaded into memory multiple times for different applications. Certain commonly used systems benefit from being made DLLs. But if only a single application is ever going to access a system, I question the need for it being made as a dynamic library in the first place.

Share this post


Link to post
Share on other sites
LessBread    1415
If I had to guess, I would guess that there are some objects that are meant to be singletons but multiple instances are being made.

Share this post


Link to post
Share on other sites
Brice Lambson    164
I'm using DLLs so that if someone modifies part of the engine, you can just change the DLL file instead of having a million exe files for all the different possibilitys, and also it's easier to release new versions with updated parts by only releasing a new DLL for that part (instead of a-whole-nother EXE file).

All my singletons have checks on them -- an exception is thrown if that should ever happen. (...and yes, I do catch these exceptions.)

Share this post


Link to post
Share on other sites
Brice Lambson    164
I fixed it! Either I accidentally flipped the SDL_BYTEORDER == SDL_BIG_ENDIAN code, or DLLs switch from Big Endian to Little Endian. I'm going to guess that I screwed it up. :D Thanks for all you thoughts tough, I did learn a few things to look out for.

Share this post


Link to post
Share on other sites
chollida1    532
Quote:
Original post by Brice Lambson
I'm using DLLs so that if someone modifies part of the engine, you can just change the DLL file instead of having a million exe files for all the different possibilitys, and also it's easier to release new versions with updated parts by only releasing a new DLL for that part (instead of a-whole-nother EXE file).

All my singletons have checks on them -- an exception is thrown if that should ever happen. (...and yes, I do catch these exceptions.)


This isn't probably something you should use exceptions for. This is more of a logic error and they are better handled by asserts see Sutter and Alexandruescu item 68.

CHeers
Chris

Share this post


Link to post
Share on other sites
Brice Lambson    164
...you're saying I should abort the entire program just because somebody accidentally created say two error logs?! It seems more logical to me just to throw an exception, catch it, and recover.

Share this post


Link to post
Share on other sites
chollida1    532
Well actually Herb Sutter is saying it, you can take it up with him, exceptions should not not be used to catch logic errors. I just happen to agree with him.

In your case you should assert, don't hack around bad practices. Enforce good ones!!

Cheers
Chris

Share this post


Link to post
Share on other sites
MichaelT    214
asserts make me shudder. brrrr. I feel it is better to handle problems properly instead. A fault should be solved and unless it is of catastrophic nature, it should not break the application. Logfiles are fine to report errors, minor or larger.

That's my point of view anyway, but I guess I am walking against the mainstream in this matter :)

Btw, it doesn't matter what Sutter or anybody else is saying. You are writing the application not them.

Share this post


Link to post
Share on other sites
Brice Lambson    164
So let me see if I'm getting this: If the error is caused by the programmer, and can be fixed by the programmer, you should assert so that the code can be corrected. If that's the case, then I can see the logic. Sorry to be so defiant, I just didn't get what you were saying.

Share this post


Link to post
Share on other sites
chollida1    532
Oops, sorry, I didn't mean to imply its a standard. He's just a well respected and very prolific C++ author. His whole point is to not provide workarounds for bad code, when you can help it. Let the user know they've done something wrong.

Infact they go onto say that the std::logic_exception will probalbly be depricated/removed from the C++ spec as it was a bad idea in the first place:)

Cheers
Chris

Share this post


Link to post
Share on other sites
Brice Lambson    164
I agree with MichaelT, too many of todays programs just give up and chrash when they should at least TRY and fix the problem first. I believe the programs we create should never crash, unless they absolutly can not fix the problem. There are so many people complaining about how windows crashes so much. I really don't think the problem is windows at all, it the lazy programmers that make programs for windows, and don't bother to facilitate for every possible error (be it user or software created).

Share this post


Link to post
Share on other sites
Anon Mike    1098
You use assert when something *cannot* happen given the logic of your program. You use it to validate your assumptions. e.g. reading an element from a sorted container might assert that the element before and after the one you read are in the right order. If an assert fires it means you have a bug in your program (or at the very least in your assumptions).

You use code (whether exceptions or whatever) in all other cases. An example is that you should never use assert to verify data that you've read from a file since anybody can come along and put garbage in the file.

To get back on topic, another thing to watch for when using dll's is that you don't allocate in one dll and free in another unless you're sure you're using a shared allocator. Even then it's probably bad practice if you can help it.

Share this post


Link to post
Share on other sites
chollida1    532
Anon_Mike very nicely restated what my point was with logic errors and exceptions, nice work, your description is very clear.

Cheers
Chris

Share this post


Link to post
Share on other sites
Brice Lambson    164
Brilliant! It all makes sense now. Thank you, I didn't quite get what chollida1's definition of a "logic error" was -- I was thinking that he meant to use it for user/file input as well, and I knew that doing that was a very bad idea.

And thanks for all the advice concerning DLLs, everyone.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this