Solved

Flush Memory Usage?

Posted on 2004-09-02
4
374 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

717 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