Solved

Working set tuning - possible?

Posted on 1998-10-30
3
276 Views
Last Modified: 2013-11-20
I need to control the amount of physical memory that my application uses. In fact, I need to establish an upper limit for the RAM used by application - I want that my application does not occupy more memory than I allow (even at cost of perfomance).

Are there some API/hacks/tricks to do that under Windows 95/98?
And what is the API/tool (like PView for NT) which can show me the amount of RAM used by my application under Windows 95/98?

I am aware of SetProcessWorkingSetSize, but it only works for NT (and even under NT I was not able to reach my goal: establishing a limit does not work, TaskManager shows that the application still uses more memory than I specified).

Regards,
Asker.
0
Comment
Question by:asker
[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
  • 2
3 Comments
 

Author Comment

by:asker
ID: 1324037
Adjusted points to 350
0
 
LVL 1

Accepted Solution

by:
sudhirbrat earned 350 total points
ID: 1324038
Youy can use Performance Data Helper (PDH) in NT to get all performance counters like Memory usage and CPU usage. The sample code to get momery usage is as follows.

#include "pdh.h"

static HQUERY            hQuery                        = NULL;
static HCOUNTER            hMemCounter;


int InitCounter()
{
        PDH_STATUS      pdhStatus;
      CHAR            CounterPath[MAX_PATH];
      CHAR            computerName[82];
      DWORD            nameLength = 80;
      
      // try to creates and initializes a unique query structure
    pdhStatus = PdhOpenQuery ( NULL, 0, &hQuery );
   
      if ( pdhStatus == ERROR_SUCCESS )
      {
            if ( GetComputerName( computerName, &nameLength ) == TRUE )
            {
                  // try for memory
                  sprintf(CounterPath, "%s%s%s", "\\\\", computerName, "\\Memory\\% Committed Bytes In Use");

                  pdhStatus = PdhAddCounter (hQuery,CounterPath, 1, &hMemCounter);

                  if ( pdhStatus != ERROR_SUCCESS )
                  {
                        // error in adding
                        return ( -3 );
                  }
            }
            else
            {
                  // error in getting computer name
                  return ( -2 );
            }
      }
      else
      {
            // error in creating the query
            return ( -1 );
      }

      // everything is ok
      return ( 0 );      
}


void CloseCounter()
{
    if ( hQuery != NULL )
      {
            // close the query
        PdhCloseQuery ( hQuery );
        hQuery = NULL;
    }
}



long GetMEMCounterValue()
{
    PDH_STATUS                        pdhStatus;
    PDH_FMT_COUNTERVALUE      pValue;
      
    if ( hQuery != NULL )
      {
        // update the collection
        pdhStatus = PdhCollectQueryData ( hQuery );

        if ( pdhStatus == ERROR_SUCCESS )
            {
                  if ( hMemCounter )
                  {
                        // get the Mem value
                        pdhStatus = PdhGetFormattedCounterValue ( hMemCounter, PDH_FMT_LONG, 0, &pValue );
                  
                        if ( pdhStatus == ERROR_SUCCESS )
                        {
                              return ( pValue.longValue );      
                        }
                        else
                        {
                              // error in getting the mem value
                              return ( -4 );
                        }
                  }
                  else
                  {
                        // memory counter is null
                        return ( -3 );
                  }
        }
            else
            {
                  // error in collection
                  return ( -2 );
            }
       }

      // error ; query not initialized
      return ( -1 );
}

For Windows 95/98, you can use registry for performance data. It will be under HKEY_DYN_DATA. You can use RegQueryValueEx to get memory usage or processor usage.
0
 
LVL 1

Expert Comment

by:sudhirbrat
ID: 1324039
The registry key HKEY_DYN_DATA in NT may not work, but it works in 95/98.


0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 76
Change owner from userA to server Local Administrators 7 74
notReplace  challenge 53 153
Not needed 13 134
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

710 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