Skip to main content
gamedev.net
🔒 Locked

Resource Management

Started by beebs1 Jul 31, 2006 at 10:59 AM 4 replies 750+ views
Original Post
beebs1
beebs1
Hi, My design is to have most resources created through a factory-like mechanism, e.g.

CxxxResource *pResource = g_pEngine->GetxxxManager()->CreateResource(...);
The manager keeps track of the resources, however, so they shouldn't be able to be deleted. Is it OK to just make their destructors protected, and make the respective manager a friend class? Actually, going even further, is there any advantage in being able to create resources without a manager? I could make the c-tors protected as well. Anyway, any thoughts/opinions would be appreciated :)
Evil Steve
Evil Steve
Quote:
Original post by beebs1
Hi,

My design is to have most resources created through a factory-like mechanism, e.g.

CxxxResource *pResource = g_pEngine->GetxxxManager()->CreateResource(...);


The manager keeps track of the resources, however, so they shouldn't be able to be deleted. Is it OK to just make their destructors protected, and make the respective manager a friend class?

Actually, going even further, is there any advantage in being able to create resources without a manager? I could make the c-tors protected as well.

Anyway, any thoughts/opinions would be appreciated :)
Yup, it's perfectly reasonable to have a private constructor and destructor. That's pretty much exactly what I do i nmy resource manager. In fact, my code looks almost identical to yours.
beebs1
beebs1
Thats great, thanks. I guess if I'm doing that I should make the copy constructor private as well to put a stop to anything nasty.
d_emmanuel
d_emmanuel
You'll want to make your assignment operator private in addition to your copy constructor. In both cases, just declare them in the private section of your class and then never define them.
treeway
treeway
my system is also very similar however i chose to keep the constructors/ destructors public. My reason was that it allows the programmer to chose if they want the resource to be managed or not. Also it was so that my resource classes did not actually depend on there being a mangeger present - this adds to the modularity of the class design and can increase the re-usability of the code. Again this was my design decision and yours may be different... its just a matter of choice.
okonomiyaki
okonomiyaki
I agree with Treeway. Though I don't think it's a big deal, but having to add the friend statement starts to break the modularity of resources. You might want to use a resource in a different system sometime, or let the user create it manually for some reason. I've never been big for private ctor's/dtor's, but that's just me.

Topic Locked

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

Sign in to reply to this topic.