|
-
May 9th, 2004, 02:05 AM
#10
Nice code, Matthew! But I have a remark (or two). This is your program:
Code:
#define MAX_64BIT_SIGNED_NO 9223372036854775807
#define MIN_64BIT_SIGNED_NO -9223372036854775808
LARGE_INTEGER Abs64( LARGE_INTEGER Value )
{
if( Value.QuadPart < 0 )
{
if( Value.QuadPart == MIN_64BIT_SIGNED_NO ) Value.QuadPart++;
Value.QuadPart *= -1;
}
return Value;
}
unsigned int TimeTaken( BOOL Start )
{
static LARGE_INTEGER Frequency;
static LARGE_INTEGER StartTime;
static LARGE_INTEGER StopTime;
double dTimeTaken;
LARGE_INTEGER Temp;
if( Start )
{
QueryPerformanceFrequency( &Frequency );
QueryPerformanceCounter( &StartTime );
return 0;
}
else
{
QueryPerformanceCounter( &StopTime );
if( StopTime.QuadPart < StartTime.QuadPart ) // Timer wrapped around
{
*-> dTimeTaken = (double)MAX_64BIT_SIGNED_NO - StartTime.QuadPart;
Temp.QuadPart = MIN_64BIT_SIGNED_NO - StopTime.QuadPart;
Temp = Abs64( Temp );
*-> dTimeTaken = (double)Temp.QuadPart;
}
else
{
dTimeTaken = (double)(StopTime.QuadPart - StartTime.QuadPart);
}
dTimeTaken = (dTimeTaken / (double)Frequency.QuadPart) * 1000.0;
return (unsigned int)dTimeTaken;
}
}
In the first marked line, dTimeTaken gets a value, but in the next marked line dTimeTaken gets a new value without using the first. So, is the first marked line really necessary?
I've read also an article from Microsoft about this function: Read this before using this function.
But, as I've said: I like your code and I'm already using it. Thx.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|