GetTickCount() 函数的作用和用法

摘要:
返回值指示毫秒数。返回值:如果正确,则返回毫秒数。标题:Winbase。h、 链接库:Coredll。库。2) 用于计算操作的时间:Start:=GetTickCount//执行耗时的操作Stop:=GetTikCount;使用时间:=/1000;//Xxx秒用于计时:voidmain(){DWORDdwLast;DWORDdwCurrent;DWORDdwInterval=1000;dwLast=GetTickCount();int i=0;而{dwCurrent=GetTickCount*();ifcontinue;//yourcodetobe executedwhenIntervalselapsedprintf;//yourcodetodeterminehentobreakifbreak;i++;dwLast=dwCurrent;printf(“Timeup!”);中断;}getchar();return;}对于一般的实时控制,GetTickCount()函数可以满足精度要求,但为了进一步提高计时精度,应使用QueryPerformanceFrequency()函数和QueryPerformanceCounter()函数。这两个函数都是VC仅为Windows9X 9X提供的高精度时间函数,需要计算机从硬件上支持高精度计时器。

原文:http://www.cnblogs.com/jxsoft/archive/2011/10/17/2215366.html

DWORD GetTickCount(void);    

1) 定义

For Release configurations, this function returns the number of milliseconds since the device booted, excluding any time that the system was suspended. GetTickCount starts at 0 on boot and then counts up from there.

在Release版本中,该函数从0开始计时,返回自设备启动后的毫秒数(不含系统暂停时间)。

For Debug configurations, 180 seconds is subtracted from the the number of milliseconds since the device booted. This allows code that uses GetTickCount to be easily tested for correct overflow handling.

在Debug版本中,设备启动后便从计时器中减去180秒。这样方便测试使用该函数的代码的正确溢出处理。

Return Values

The number of milliseconds indicates success.

返回值:如正确,返回毫秒数。

Header: Winbase.h.
Link Library: Coredll.lib.

2) 应用

用来计算某个操作所使用的时间:   

GetTickCount() 函数的作用和用法第1张  Start:=GetTickCount;   
GetTickCount() 函数的作用和用法第1张   ...//执行耗时的操作   
GetTickCount() 函数的作用和用法第1张   Stop:=GetTickCount;   
GetTickCount() 函数的作用和用法第1张   TimeUsed:=(Stop-Start)/1000;     //使用了xxx秒

用来定时:  

GetTickCount() 函数的作用和用法第1张
GetTickCount() 函数的作用和用法第1张void main() 
GetTickCount() 函数的作用和用法第7张{
GetTickCount() 函数的作用和用法第8张  DWORD dwLast;
GetTickCount() 函数的作用和用法第8张  DWORD dwCurrent;
GetTickCount() 函数的作用和用法第8张  DWORD dwInterval = 1000;
GetTickCount() 函数的作用和用法第8张  dwLast = GetTickCount();
GetTickCount() 函数的作用和用法第8张  int i = 0;
GetTickCount() 函数的作用和用法第8张  while(true)
GetTickCount() 函数的作用和用法第14张     {
GetTickCount() 函数的作用和用法第8张        dwCurrent = GetTickCount();
GetTickCount() 函数的作用和用法第8张        if( dwCurrent - dwLast < dwInterval )
GetTickCount() 函数的作用和用法第8张        continue;
GetTickCount() 函数的作用和用法第8张         //your code to be executed when interval is elapsed
GetTickCount() 函数的作用和用法第8张        printf("dwLast,dwCurrent,diff:%d,%d,%d ",dwLast,dwCurrent,dwCurrent-dwLast);
GetTickCount() 函数的作用和用法第8张         //your code to determine when to break
GetTickCount() 函数的作用和用法第8张        if( i > 10 ) break;
GetTickCount() 函数的作用和用法第8张        i++;
GetTickCount() 函数的作用和用法第8张        dwLast = dwCurrent;
GetTickCount() 函数的作用和用法第8张        printf("Time is up!");
GetTickCount() 函数的作用和用法第8张        break;
GetTickCount() 函数的作用和用法第26张     }
GetTickCount() 函数的作用和用法第8张   getchar();   
GetTickCount() 函数的作用和用法第8张   return;
GetTickCount() 函数的作用和用法第29张

对于一般的实时控制,使用GetTickCount()函数就可以满足精度要求,但要进一步提高计时精度,就要采用QueryPerformanceFrequency()函数和QueryPerformanceCounter()函数。这两个函数是VC提供的仅供Windows   9X使用的高精度时间函数,并要求计算机从硬件上支持高精度计时器。

以上引用:

http://www.wesoho.com/article.asp?id=2072

http://bitboy.blog.edu.cn/user1/19986/archives/2005/1001846.shtml

免责声明:文章转载自《GetTickCount() 函数的作用和用法》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇微服务架构设计如何打开dwg文件下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

canvas基础绘制矩形(1)

1.画布基础知识画布元素是HTML5中添加的一个重要元素,专门用于绘制图形。然而,画布本身不具备绘制图形的能力。将画布元素放置在页面上相当于在页面上放置矩形“画布”。我们可以使用js脚本在“画布”上绘制图形。...

FastDFS安装

FastDFS安装包FastDFS安装包百度网盘密码aj4f下载后把安装包移动到服务器里面这里我把安装包放在opt/FastDFSFastDFS安装安装环境在本地安装就需要安装gcc环境yum-yinstallcmakemakegcc-c++在阿里服务器因为帮你配置好了的解压libfastcommon到指定目录解压-C指定解压的目录#解压[root@rzkF...

微信小程序知识点总结--组件

aspectFill缩放模式保持缩放图像的纵横比,并且只能完全显示图像的短边。也就是说,图片通常只在水平或垂直方向上是完整的,而另一个方向会被截取。...

Java 安全之:csrf攻击总结

最近,我在维护一些旧项目。在调试期间,我发现请求被反复拒绝。我仔细查看了项目的源代码,发现存在csrftoken验证。我借此机会了解了csrf攻击,并将其总结成一篇论文。受攻击的网站无法阻止攻击。在整个过程中,攻击者无法获取受害者的登录凭据,只能“冒充”。CSRF攻击成功,因为服务器将攻击者发送的请求误认为是用户的请求。服务器通过验证请求是否携带正确的令牌来...

一起学习Avalonia(十二)

可以使用数据模板自定义和显示数据模板模板。文档中介绍了Avalonia的基本数据模板。PublicstringFirstName{get;set;}publicstringLastName{get;set;}扩展使用文档最后介绍了扩展使用,包括2个模型。Student和Teacher。在MainWindowViewModel中创建属性Content。此属性是...

[Oracle]

MyOralceLinux6.5isrunningonVirtualBox.Basicsettingsis4Gmemory,50Ghard-disk,autopartitionwheninstallOL6.5.**Followingseriesofoperationsneedrootprivilege.1.Edit/etc/hostsAddyourhostn...