Sign in to follow this  
Chris_F

Initialising library

Recommended Posts

I have an Application class, and it uses the PHYSFS library, which requires that the functions PHYSFS_init() and PHYSFS_deinit() be called to set up the library and then clean it up.

In my Application.cpp I simply have this:

[code]
class PHYSFS
{
public:
PHYSFS()
{
PHYSFS_init(NULL);
}
~PHYSFS()
{
PHYSFS_deinit();
}
};

PHYSFS physfs;
[/code]

Is this a good idea?

Share this post


Link to post
Share on other sites
That's fine as long as you can avoid being bitten by the "static initialization order fiasco".

I.e. don't use the same technique for anything that depends on any of the other static constructors also having been run.

Share this post


Link to post
Share on other sites
May be a better idea to have an object that represents the life of your application, and have the PHSYFS instance be a member of it. I tend to have an Application class that is created as a local variable in WinMain and have objects that live for the entire application be members of that.

This makes it very clear and explicit exactly what order things are created and destroyed, and plays nice with exceptions as well.

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