Solved

Working set tuning - possible?

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now