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[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.