Implicit Resource management Design–Idea

An idea came into my mind today. Why not just make an implicit(automatic) resource management system instead of having some kind of an external resource management system.

Ever since the way I did it was having an external resource manager that I would then use to create the resource I want. Take a look at this sample code below.

Code Snippet 1
  1. void FunkyFunkFunk( void )
  2. {
  3.     Texture *pTexture = TextureManager::GetInstance()->CreateTexture( … );
  4.     
  5.     // Use texture
  6.     pTexture->DoSomething();
  7.     pTexture->DoMoreStuff();
  8.     pTexture->Render();
  9.  
  10.     // We're done with the texture. Remove texture from the manager
  11.     TextureManager::GetInstance()->DeleteTexture( pTexture );
  12. }

As you can see, we create a texture through a texture resource manager called TextureManager and once we’re done with the texture we go through the TextureManager again to remove that created resource.  It’s not really much of a big deal but what if we could just hide the resource management code stuff yet still having all the benefits and convenience of managing your resources? That’s where I thought and said, “Why not just place the manager inside the resource class instead and handle the resource management creation and deletion through the constructor and destructor of the resource respectively?”. hmmm….

 

– MrCodeSushi

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s