Saturday 9 September 2006

Priorities in Win32

I found that increasing process priority is a nice (asd) way to improve performances of my Powerglove, expecially on less powerful machines.

The glove itself produces trains of data at ~500hz: casts ten bytes and then waits 2ms. Too bad, I couldn't leave the scheduler the privilege to subtract more time.

What follows is a short C function to change priority of the running process:


void prioritizza(DWORD value) {
// PID of this process
int processID = GetCurrentProcessId();

// handler of this process
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, processID);

// actually sets priority
SetPriorityClass(hProcess, value);
};


Remember to include "windows.h" , for many structures and constants are defined there.

In the end, as values, I used the constant HIGH_PRIORITY_CLASS. Here follow the constants you could use in your own programs:
  • IDLE_PRIORITY_CLASS
  • BELOW_NORMAL_PRIORITY_CLASS
  • NORMAL_PRIORITY_CLASS
  • ABOVE_NORMAL_PRIORITY_CLASS
  • HIGH_PRIORITY_CLASS
  • REALTIME_PRIORITY_CLASS
As you could imagine, they are ordered by increasing performance.

No comments: