Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualSandman

Posted 05 April 2013 - 08:22 AM

#pragma once

class IResource
{
public:
int GetRef(void) const { return m_numRef; }

void AddRef(void) { m_numRef += 1; }
virtual void Release(void) = 0;

protected:

int m_numRef;
};

 

IResource has absolutely nothing to do with resources. It's a reference counter. Call it IReferenceCounter. Also, never expose protected data, it's as much a no-no as public data. Your reference counting implementation as it stands is going to be extremely tightly coupled to absolutely everything that touches it.

 

Far better to remove it entirely and use RAII and smart pointers as appropriate to automate that stuff. Remember 'has a' vs. 'is a' relationships. TextureResources and EffectResources might HAVE ref counted components, but they don't necessarily need to BE ref counted themselves, so long as what they contain is managed properly. Do this and you can dispose of that coupling entirely.


#2Sandman

Posted 05 April 2013 - 08:21 AM

#pragma once

class IResource
{
public:
int GetRef(void) const { return m_numRef; }

void AddRef(void) { m_numRef += 1; }
virtual void Release(void) = 0;

protected:

int m_numRef;
};

 

IResource has absolutely nothing to do with resources. It's a reference counter. Call it IReferenceCounter. Also, never expose protected data, it's as much a no-no as public data. Your reference counting implementation as it stands is going to be extremely tightly coupled to absolutely everything that touches it.

 

Far better to remove it entirely and use RAII and smart pointers as appropriate to automate that stuff. Remember 'has a' vs. 'is a' relationships. TextureResources and EffectResources might HAVE ref counted components, but they don't necessarily need to BE ref counted themselves, so long as what they contain is managed properly. 


#1Sandman

Posted 05 April 2013 - 07:58 AM

#pragma once

class IResource
{
public:
int GetRef(void) const { return m_numRef; }

void AddRef(void) { m_numRef += 1; }
virtual void Release(void) = 0;

protected:

int m_numRef;
};

 

IResource has absolutely nothing to do with resources. It's a reference counter. Call it IReferenceCounter.

 

Or better yet, remove it entirely and use RAII and smart pointers as appropriate to automate that stuff. Remember 'has a' vs. 'is a' relationships. TextureResources and EffectResources might HAVE ref counted components, but they don't necessarily need to BE ref counted themselves, so long as what they contain is managed properly. 


PARTNERS