-
Running out of memory
I wrote a program that opens .htm files, exchanges certain characters for the month, day, and year that the user inputs. It works the first time the program is ran, but everytime I try to run it a second time, it tells me I have insufficent memory. If I reboot my machine, I can run once more. Is there a command I can use that will free up whatever is being left behind.
I can post the program if you need to see it, but it is really long, somewhere around 1100 lines.
Thank you for any help or suggestions you might have:)
-
>there a command I can use that will free up whatever is being
>left behind.
No, you have to take care for that yourself.
-
How are you alocating your memory? Are you using new without delete?
-
This is a shortend down version of what I'm doing:
Code:
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <string>
#include <io.h>
using namespace std;
string month;
string day;
string year;
string weekday;
//The following are the functions for the different htm's
/////////////////////////////////////////////////////
//Function that prepares finalcwchartlist
/////////////////////////////////////////////////////
void cwchartlistfinal(ifstream& in_stream, ofstream& out_stream)
{
char next;
in_stream.get(next);
while (! in_stream.eof())
{
if (next == '*')
out_stream << "";
else
if (next == '@')
{out_stream << month;
}
else
if (next == '$')
{ out_stream << day;
}
else
if (next == '!')
{
out_stream << year;
}
else
if (next == '^')
{
out_stream << weekday;
}
else
out_stream << next;
in_stream.get(next);
}
}
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
int main(int argc, char * argv[])
{
/*
cout << "ChartList Creator \n";
cout << " Enter Month:";
cin >> month;
cout << " Enter Day: ";
cin >> day;
cout << " Enter Year: ";
cin >> year;
cout << " Enter Day of the Week: ";
cin >> weekday;
*/
month = argv[1];
day = argv [2];
year = argv [3];
weekday = argv [4];
//////////////////////////////////////////////////////
// Edits newcwchartlist for the internet
/////////////////////////////////////////////////////
ifstream finnewcwchartlist;
ofstream foutfinalcwchartlist;
cout << "Begin editing cwchartlist.\n";
finnewcwchartlist.open("newcwchartlist.htm");
if (finnewcwchartlist.fail())
{
cout << "newcwchartlist opening failed.\n";
exit(1);
}
foutfinalcwchartlist.open("finalcwchartlist.htm");
if (foutfinalcwchartlist.fail())
{
cout << "finalcwchartlist opening failed.\n";
exit(1);
}
cwchartlistfinal(finnewcwchartlist, foutfinalcwchartlist);
finnewcwchartlist.close();
foutfinalcwchartlist.close();
cout << "End of editing finalcwchartlist.\n";
///////////////////////////////////////////////////////
return 0;
}
I run this 14 times, but with different file names. I don't understand what the problem could be, after the files are closed, they shouldn't take up anymore space right?