Jump to content

  • Log In with Google      Sign In   
  • Create Account


bullfrog

Member Since 28 Feb 2012
Offline Last Active Jan 06 2014 04:51 AM

Topics I've Started

Class Function Overloading Method Question

11 May 2012 - 02:27 AM

Hi, I always wondered what is the right thing to do in this situation. This is a quick example, the third inheritance makes no sense but it adds more context to the question.

class CModel
{
    void Draw(CRenderer& _rRenderer);
}
class CPlayerModel : public CModel
{
    void Draw(CRenderer& _rRenderer, const CVector3& _krPlayerPosition);
}
class CExamplePlayerModel : public CPlayerModel
{
    void Draw(CRenderer& _rRenderer, const CVector3& _krPlayerPosition, void* _pAnotherParameter);
}

As the hierarchy extends, the Draw function requires another parameter for the model to draw correctly. Is this correct OOP? What stops a user from using the parents draw function and therefore breaking the game?

C++ Memory Usage & Allocation

07 March 2012 - 01:37 AM

Hi,

I am currently working on a game and I am having some difficulty understanding why my memory usage is so high.

So for testing I created a simple project to that allocates memory.

#include <iostream>

unsigned int g_uiTotalClusterMemory = 0;
unsigned int g_uiTotalCubeMemory = 0;

class CCube
{
public:
  CCube() {}
~CCube() {}

private:
int m_i1;
int m_i2;
};

class CCluster
{
public:
CCluster()
{
  for (int i = 0; i < s_kiX; ++i)
  {
   for (int j = 0; j < s_kiY; ++j)
   {
	for (int k = 0; k < s_kiZ; ++k)
	{
	 m_pCube[i][j][k] = new CCube();
	 g_uiTotalCubeMemory += sizeof(CCube);
	}
   }
  }
}

~CCluster() {}

private:
static const int s_kiX = 16;
static const int s_kiY = 16;
static const int s_kiZ = 16;
CCube* m_pCube[s_kiX][s_kiY][s_kiZ];
};

CCluster* g_pCluster = 0;

void main()
{
const int kiNumClusters = 16 * 16 * 16;

//Instance clusters
g_pCluster = new CCluster[kiNumClusters];

//Calculate memory useage for all clusters
g_uiTotalClusterMemory = sizeof(CCluster) * kiNumClusters;

//Convert bytes to megabytes
g_uiTotalClusterMemory /= 1024;
g_uiTotalClusterMemory /= 1024;
g_uiTotalCubeMemory /= 1024;
g_uiTotalCubeMemory /= 1024;

//Calculate total memory
unsigned int g_uiTotalMemory = g_uiTotalClusterMemory + g_uiTotalCubeMemory;

//Output memory values to screen
std::cout << "Total Cube Memory Used:" << g_uiTotalCubeMemory << "\n";
std::cout << "Total Cluster Memory Used:" << g_uiTotalClusterMemory << "\n";
std::cout << "Total Memory Used:" << g_uiTotalMemory << "\n";

//Pause
float fCaek = 0.0f;
std::cin >> fCaek;
}

The code outputs the following:

Total Cube Memory Used:128
Total Cluster Memory Used:64
Total Memory Used:192

But windows taskmanager and process explorer both tell me the program is using 329,624k of memory. Is this test setup correctly? If so why is my program using more memory then I am allocating?

Thanks!

EDIT: I am using Visual Studio 2010 with the program running outside of the IDE, release build.

PARTNERS