Solved

Working set tuning - possible?

Posted on 1998-10-30
3
277 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

628 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