Running out of memory

This is a discussion on Running out of memory within the C++ Programming forums, part of the General Programming Boards category; I wrote a program that opens .htm files, exchanges certain characters for the month, day, and year that the user ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    6

    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

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    >there a command I can use that will free up whatever is being
    >left behind.

    No, you have to take care for that yourself.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    591
    How are you alocating your memory? Are you using new without delete?

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    6
    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?
    Last edited by RustGod; 03-20-2002 at 02:09 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with insert/delete binary search tree
    By Nazgulled in forum C Programming
    Replies: 39
    Last Post: 03-25-2009, 04:24 PM
  2. multithreading question
    By ichijoji in forum C++ Programming
    Replies: 7
    Last Post: 04-12-2005, 10:59 PM
  3. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 12:33 PM
  4. Detecting where an application is running in memory...
    By CompiledMonkey in forum C Programming
    Replies: 1
    Last Post: 08-12-2003, 01:25 AM
  5. Is it necessary to write a specific memory manager ?
    By Morglum in forum Game Programming
    Replies: 18
    Last Post: 07-01-2002, 01:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21