Jump to content

  • Log In with Google      Sign In   
  • Create Account


We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


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


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
  CCube() {}
~CCube() {}

int m_i1;
int m_i2;

class 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() {}

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";

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?


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