# [SDL]high resolution timers?

This topic is 3663 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

on this page http://www.libsdl.org/cgi/docwiki.cgi/SDL_GetTicks there is a note that says: NOTE: On platforms with high resolution timers, you can get the number of microseconds. Will add details after further investigations. Does anyone know anything more about this?

##### Share on other sites
Use the source!

For example, SDL 1.2 on Windows appears not to use a high resolution timer (due to issues with QueryPerformanceCounter on Win2K apparently).

##### Share on other sites
well i did look through the header file SDL_timer.h but I did not find anything that talked about it.

##### Share on other sites
You would have to look through the actual source code, not just the header. Here is a snippet from the win32 timer directory
void SDL_StartTicks(void){	/* Set first ticks value */#ifdef USE_GETTICKCOUNT	start = GetTickCount();#else#if 0 /* Apparently there are problems with QPC on Win2K */	if (QueryPerformanceFrequency(&hires_ticks_per_second) == TRUE)	{		hires_timer_available = TRUE;		QueryPerformanceCounter(&hires_start_ticks);	}	else#endif	{		hires_timer_available = FALSE;		timeBeginPeriod(1);		/* use 1 ms timer precision */		start = timeGetTime();	}#endif}Uint32 SDL_GetTicks(void){	DWORD now, ticks;#ifndef USE_GETTICKCOUNT	LARGE_INTEGER hires_now;#endif#ifdef USE_GETTICKCOUNT	now = GetTickCount();#else	if (hires_timer_available)	{		QueryPerformanceCounter(&hires_now);		hires_now.QuadPart -= hires_start_ticks.QuadPart;		hires_now.QuadPart *= 1000;		hires_now.QuadPart /= hires_ticks_per_second.QuadPart;		return (DWORD)hires_now.QuadPart;	}	else	{		now = timeGetTime();	}#endif	if ( now < start ) {		ticks = (TIME_WRAP_VALUE-start) + now;	} else {		ticks = (now - start);	}	return(ticks);}

As rip-off said, and you can see, they are just using timeGetTime( ) and not the high-res timer. Looking through the unix source, it looks like they try to use clock_gettime, but default to gettimeofday.

1. 1
2. 2
3. 3
4. 4
Rutin
18
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631423
• Total Posts
3000003
×