RAM Booster

11 02 2009

description4

 

 

Computer RAM memory is very important because it allows the application running quickly. When we run large number of programs it may consumes all RAM memory, then our computer has to use hard disk as the memory. But the hard disk is very slower than the RAM memory, so the computer becomes too slow.

howcanidoit5

 

 

So we need to free up or releasing some memory safelyPSAPI having different APIs to implement this. The EmptyWorkingSet API function removes as many pages as possible from the working set of the specified process. So first of all we need to get the process handles by using the API EnumProcesses. Please look on my previous post to see how to get the handles of all the process running in your machine.

mycodesnippet4

 

 

void BoostMyRAM()
{ 
   // Get the list of process identifiers.  
   DWORD aProcesses[1024], cbNeeded, cProcesses;
   unsigned int i;
  
   //This returns a list of handles to processes running on
   //the system as an array.
   if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
      return;
  
   // Calculate how many process identifiers were returned.  
   cProcesses = cbNeeded / sizeof(DWORD);
  
   for ( i = 0; i < cProcesses; i++ )
   {
      if( aProcesses[i] != 0 )
      {
         // Get a handle to the process.  
         HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
            PROCESS_VM_READ | PROCESS_ALL_ACCESS,
            FALSE, aProcesses[i] );
        
         // Get the process name.  
         if (NULL != hProcess )
         {
            TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
            HMODULE hMod;
            DWORD cbNeeded;
           
            if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) )
            {
               //This function returns the short name for a module,
               //typically the file name portion of the EXE or DLL
               GetModuleBaseName( hProcess, hMod, szProcessName,
                  sizeof(szProcessName)/sizeof(TCHAR) );
            }
           
            CString str = szProcessName;
           
            //specify the process names
            //or choose whole processes
            if(0 == str.CompareNoCase(_T("devenv.exe")))
            {
               //Removes as many pages as possible from the
               //working set of the specified process.
               if( !EmptyWorkingSet(hProcess) )
               {
                  // AfxMessageBox(_T("Failed") ); //error
               }
            }
         }        
      }
   }    
}

mynote4

 

 

After executing the sample code please look on the Task Manager and check any variation in the memory usage of the given application.

Don’t forget to include Psapi.lib to library modules.

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: