Solved

Working set tuning - possible?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Complete beginner needs help making a cron job 9 110
ShiftLeft challenge 21 78
How to convert MFC::CString to UTF8 wchar_t* 10 148
Not needed 13 95
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

863 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

19 Experts available now in Live!

Get 1:1 Help Now