View Single Post
Old 2003-10-17, 11:38   #2
xilman
Bamboozled!
 
xilman's Avatar
 
"π’‰Ίπ’ŒŒπ’‡·π’†·π’€­"
May 2003
Down not across

31×359 Posts
Default Re: Tray icon OS/CPU/Uptime prog

Quote:
Originally posted by PrimeCruncher
This program uses a generic icon which, when the mouse hovers over it, displays the OS, the speed and manufacturer of the CPU, and the uptime of the system.
Not sure it works properly. I also think I know what you need to do to fix it. On my system I get

XP Intel -1762: 1 days, 2 hours, 37 minutes


Some of this is correct. It is an Intel P4 running XP Pro. According to another uptime program:

% /Z/uptime.exe
\\MSRC-RAT has been up for: 1 day(s), 2 hour(s), 38 minute(s), 6 second(s)
%

Note that your program doesn't properly handle singular and plural units of time. You should test for 1 of each unit and drop the 's' in those cases. This might sound fussy, but it does show whether you care enough to do a job properly rather than cutting corners for simplicity.

The real problem, though, is the displayed clock speed. My machine is actually a 2.53GHz machine. Converting the displayed MHz to GHz, we get -1.762 GHz, which is clearly wrong.

I observe that 2^32 - 2.53*10^9 is 1.765*10^9. It seems virtually certain that your code internally stores Hz, and not MHz, and does so in a signed 32-bit number. Any frequency over 2^31 Hz (about 2GHz) is going to overflow the variable.

There are several workarounds, some better than others. A poor one is to use a 32-bit unsigned variable. This will break when clock frequencies increase beyond 4.29GHz, which is likely to happen within a year or so. A much better one is to use a larger variable, 64 bits probably, which will be adequate for a long time to come. Another possibility, intermediate in desirability in my view, is to obtain the clock frequency in larger units, perhaps MHz, so that a 32-bit variable has an adequate range.

Paul
xilman is offline   Reply With Quote