I am working on a texture synthesis project. I am almost finished, however my process is taking ~2gb of memory while it is running. I thought I was freeing all of my calloc'ed arrays, but I could be wrong. C++ isn't my specialty.
I know triple pointers were the wrong way to go about it in C++ but I am just more comfortable with them at the moment. Let me know if you need to see more code. Thank you.
MetaPic declaration
class MetaPic
{
public:
Pic* source;
Pixel1*** meta;
int x;
int y;
int z;
MetaPic();
MetaPic(Pic*);
MetaPic(const MetaPic&);
MetaPic(int, int, int);
MetaPic& operator=(const MetaPic&);
~MetaPic();
void allocateMetaPic();
void copyPixelData();
void copyToOutput(Pic*&);
void copyToMetaOutput(MetaPic&, int, int);
void copyToSample(MetaPic&, int, int);
void freeMetaPic();
};
Allocating the triple pointer
void MetaPic::allocateMetaPic()
{
meta = (Pixel1***)calloc(x, sizeof(Pixel1**));
for(int i = 0; i < x; i++)
{
meta[i] = (Pixel1**)calloc(y, sizeof(Pixel1*));
for(int j = 0; j < y; j++)
{
meta[i][j] = (Pixel1*)calloc(z, sizeof(Pixel1));
}
}
}
Deallocating the triple pointer
void MetaPic::freeMetaPic()
{
for(int j = 0; j < y; j++)
{
for(int i = 0; i < z; i++)
free(meta[i][j]);
}
for(int i = 0; i < x; i++)
free(meta[i]);
free(meta);
}
Destructor
MetaPic::~MetaPic()
{
freeMetaPic();
}
= Operator
MetaPic& MetaPic::operator=(const MetaPic& mp)
{
freeMetaPic();
source = mp.source;
x = mp.x;
y = mp.y;
z = mp.z;
allocateMetaPic();
copyPixelData();
return *this;
}
Copy constructor
MetaPic::MetaPic(const MetaPic& mp)
{
source = mp.source;
x = mp.x;
y = mp.y;
z = mp.z;
allocateMetaPic();
copyPixelData();
}
allocateCountandfreeCountinteger that get incremented every time you callallocandfreerespectively. Then you can compare the values and see if they match.