Solved

Flush Memory Usage?

Posted on 2004-09-02
4
360 Views
Last Modified: 2010-04-01
Hello!  I have been adding to this little LAN Chat app I wrote...  today I was checking the Processes in Taskman and noticed that the memory this program uses increases little by little as it runs...  is there some code I can add that will "flush" the memory and keep usage to a minimum without messing with the program too much.  Code is below:

#include <iostream>
#include <stdlib.h>
#include <conio.h>
#include <iomanip>

using namespace std;

int main(int argc, char *argv[])
{
  std::string target;
  std::string GetStarted = "net send ";
  std::string spacer = " ";
  std::string messg;
 
 
  cout << "Welcome to LAN Messenger 1.0 beta 3.\n";
  cout << "Enter /h in any field at anytime for help.\n";
  cout << "\n";
  system("Pause");
  goto MainTitle;
 
MainTitle:
  system("CLS");
  cout << "\n";
  cout << "|    __   __       __  |__   __  _|_  \n";
  cout << "|_, (__( |  )     (___ |  ) (__(  |_, \n";
  cout << "                                v1.0 b3\n";
  goto MainMenu;
 
MainMenu:
  cout << "\n";
  cout << "\n";
  cout << "               OPTIONS: \n";
  cout << "\n";
  cout << "            CTRL+C -> Chat\n";
  cout << "            CTRL+H -> Help\n";
  cout << "            CTRL+X -> Exit\n";
  char ch;
  while (ch = getch())
  {
  if(ch == 0x08)
      {
            goto Help;
      }
  if(ch == 0x18)
    {
        cout << "Have a nice day";
        return 0;
    }
  if(ch == 0x03)
    {
        goto Begin;
    }
                  
  }                                
 

Begin:
  system("CLS");
  cout << "Target: ";
  cin >> target;
  if(target == "/h" || target == "/H")
  {
      system("CLS");
      goto Help;
  }
  if(target == "/m" || target == "/M")
  {
        system("CLS");
        goto MainMenu;
  }
 
  if(target == "//")
  {
      system("CLS");
      cout << "\n";
      cout << "Connection terminated.\n";
      cout << "\n";
      system("Pause");
      return 0;
  }        
 
 
  do
  {
      cout << "Connection to " << target << "\n";
      cout << "Message: ";
      getline(cin,messg);
     
      if(messg == "//")
      {
          system("CLS");
          cout << "\n";
          cout << "Connection to " << target << " terminated!\n";
          cout << "\n";
          system("Pause");
      }  
     
      if(messg == "/")
      {
          goto Begin;
      }    
     
      if(messg == "/h" || messg == "/H")
      {
          system("CLS");
          goto Help;
      }
        if(messg == "/m" || messg == "/M")
        {
              system("CLS");
              goto MainMenu;
        }
               
      std::string command = GetStarted + target + spacer + messg;
      system(command.c_str());
      system("CLS");
  }while (messg != "//");  
 
Help:
  system("CLS");
  cout << "*Target* <- Enter target users network name, or computer name.\n";
  cout << "*Message* <- Enter your message.\n";
  cout << "To change target users, enter / in the message field.\n";
  cout << "To view help file, enter /h in the message field.\n";
  cout << "To return to Main Menu enter /m in any field.\n";
  cout << "To exit, enter // in the message field.\n";
  cout << "\n";
  system("Pause");
  goto Begin;


  return 0;    

}


Thanks in advance!

Regards,
Tony
0
Comment
Question by:fattumsdad
4 Comments
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 11968224
You can use a debugging memory allocation library to help you isolate
memory leaks.

http://dmalloc.com

0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 150 total points
ID: 11968244
There's no reason for any 'malicious' increase of memory usage in your program. Which field in the task manager are you watching? If you mean the 'maximum memory load', that's just a high-water mark of the highest memory consumption during the runtime of your program and will never decrease. The value of interest actually is the 'virtual memory' field.
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 11969054
JKR,

I go to the Task Manager and click on Processes, I'm looking under the "Mem Usage" column.  Is there a way I can bring that number (about 722K) down?  :)

Regards,
Tony
0
 
LVL 3

Accepted Solution

by:
Indrawati earned 150 total points
ID: 11969299
Hi

Just note that the Mem Usage colum in the task manager does not 100% reflect the amount of memory you app consumes. It's explained in this article:

http://www.codeproject.com/system/howbig.asp
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question