Since I was in scrutinize mode, I noticed that I saw an increase in memory usage every time I clicked the mouse button. About 100K every click.
I isolated it down to a bit of code I use to read a file then parse the data. I could not see why it was increasing memory usage. As an experiment, I swapped all the AppGameKit string functions to C++ functions,
and now the issue is gone. Something weird is going on with the string functions: Left(), Right(), Mid() and Asc(). I knew about Str() where we need to assign to char* then delete[] the string. But I found nothing about the other string functions having similar protocols.
such as:
char* strTemp = agk::Str(objExists);
MainLoop.locOBJ = "_OBJ" + string(strTemp);
delete[] strTemp;
Now, it takes 10 clicks instead of 1 to see a 100K change. I am sure this is due to my replacing all the string functions except for Asc().
Code after swapping to C++ functions:
string GetParameter(std::string paraName, std::string fileName)
{
string stuff;
string theRest;
string isolated;
string testIT;
int testIT2;
stuff = "";
theRest = "";
isolated = "";
agk::SetFolder("");
agk::SetFolder("media");
if (agk::GetFileExists(fileName.c_str()))
{
agk::OpenToRead(1, fileName.c_str());
stuff = agk::ReadString(1);
paraName = paraName + "=";
for (unsigned int i = 0; i <= (stuff.length()); i++)
{
//if (agk::Mid(stuff.c_str(), i, (paraName.length())) == paraName)
//{
// theRest = agk::Mid(stuff.c_str(), i + agk::Len(paraName.c_str()), (stuff.length()) - i);
// break;
//}
testIT=stuff.substr(i, paraName.length());
if ((stuff.substr(i,paraName.length()) ) == paraName)
{
theRest = stuff.substr(i + paraName.length(), (stuff.length()) - i);
break;
}
}
for (unsigned int i = 0; i <= (theRest.length()); i++)
{
testIT2 = agk::Asc((theRest.substr(i, 1)).c_str());
if ((agk::Asc((theRest.substr(i, 1)).c_str()) == 10) || ((agk::Asc((theRest.substr(i, 1)).c_str()) == 13)))
{
isolated = theRest.substr(0,i);
break;
}
}
agk::CloseFile(1);
}
return isolated;
}