Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Flush Memory Usage?

Posted on 2004-09-02
4
Medium Priority
?
384 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 600 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 600 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

877 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