Jump to content

TimerInit() handle


Recommended Posts

Is the TimerInit handle destroyed if you overwrite the originating variable? I doubt it... but that would mean there's no way to destroy the Timer handle natively. I've seen Timer UDFs, but I was just curious as to the repercussions of creating hundreds of thousands on timer handles, by debugging certain things for a while to get average times.

This is another time-wasting question that doesn't have any real goal or purpose, outside satisfying my curiosity! So I figured chat was a good place for it, once again. ^.^

Doesn't this create Timer handles that aren't getting destroyed? Does it hurt anything to use timers at the beginning of a script and never use them again? Aren't they just sitting there running?

While 1
     $TimerHandle = TimerInit()
     $TimerDiff = TimerDiff($TimerHandle)
WEnd

SIGNATURE_0X800007D NOT FOUND

Link to comment
Share on other sites

Doesn't this create Timer handles that aren't getting destroyed? Does it hurt anything to use timers at the beginning of a script and never use them again? Aren't they just sitting there running?

While 1
     $TimerHandle = TimerInit()
     $TimerDiff = TimerDiff($TimerHandle)
WEnd

 

No, you are overwriting both variables in every loop with that code, plus what JohnOne said.

Edited by czardas
Link to comment
Share on other sites

Ahh! I hadn't actually tried looking at what TimerInit() returned. It returns the same as _Timer_Init() [uDF included with AutoIt 3.3.10.0], which is just the current timestamp.

The documentation makes it sound so mysterious, saying that you shouldn't do anything with the TimerInit() return and it should be treated as a handle... :huh2:

http://screencast.com/t/X5bjXCk6s0yg

Anywho, that perfectly answers my question. I could have figured that one out if I had just checked the return from TimerInit()!

Thanks JohnOne & czardas! :lol:

Edited by BinaryBrother

SIGNATURE_0X800007D NOT FOUND

Link to comment
Share on other sites

TimerInit does not return a timestamp, it returns what Valik termed as an opaque handle, TimerDiff uses that handle to calculate the difference in time between the Init and the Diff.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

He didn't say it is, he said it should be treated as.

I'm not sure what it is you're saying here.

It is still not a real handle because that would cause a horrible memory leak if all those handles were created and not freed. Notice there is no TimerDestroy function.

That's why he called it an opaque handle, as in it's not a handle but a pointer to something else. But it's not a timestamp as others were saying above, which is what I was trying to point out. This stuff is above my ability level, I just wanted people to not get the wrong idea as to what timerinit returns.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Even if it were a timestamp, there's no way to use it as one. You can't subtract two timerinits and get a time difference, at least not directly in a format that makes sense.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Probably not, because I don't know how it is implemented, but I don't need to, Timerdiff deals with that.

One might have a definition of what a standard timestamp might be, but however you cook it Timerdiff is a timestamp for Timerinit, regardless of it's type.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

wiki defines a timestamp as "a sequence of characters or encoded information identifying when a certain event occurred, usually giving date and time of day, sometimes accurate to a small fraction of a second"

If that is not what TimerInit is, I'll eat my undercrackers.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

:pirate:

#include <WinAPISys.au3>

Global $iStart = TimerInit()
Global $iStart2 = _WinAPI_QueryPerformanceCounter()
ConsoleWrite("TimerInit: " & $iStart & @LF)
ConsoleWrite("QueryPerformanceCounter: " & $iStart2 & @LF)

Sleep(2000)
ConsoleWrite(TimerDiff($iStart2) & @LF)
ConsoleWrite((TimerInit() - $iStart2)*1000 / _WinAPI_QueryPerformanceFrequency() & @LF)
Edited by funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

It's never actually documented what the return type is. It could change in the next release to something completely different, so any code you write that uses the return value for anything other than TimerDiff could be broken and it wouldn't even be mentioned in the changelog.

That's why Valik said to treat it as a handle: something which only has meaning internally.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...