Solved

Working set tuning - possible?

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand LInux Boot partition remotly 3 90
only14 challenge 19 76
has77  challenge 9 85
java ^ examples 8 65
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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