-
QueryPerformanceFreqency and QueryPerformanceCounter
hello , i try make a customizable delay out of QueryPerformanceFreqency and QueryPerformanceCounter i try is as i googled for 6+ hours and couldnot find anything to work with but i am not sure how to get it working.
Problem for me is that i have no idea how to use QueryPerformanceCounter so that value would be updating constantly not only 1 value and finished.
What sould i use in code to make values update itself very fast automatically?
for example id like QueryPerformanceCounter to update its value that is compared(<=) to calculation with fixed values. QueryPerformanceFreqency+QueryPerformanceCounter*2 to get a 2sec delay as soon as value is equal or larger than other and then
use if true to do delayed task.
How to make QueryPerformanceCounter update itself in comaprison to calculation that would be with fixed values?
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
Quote:
Originally Posted by
1248
hello , i try make a customizable delay out of QueryPerformanceFreqency and QueryPerformanceCounter i try is as i googled for 6+ hours and couldnot find anything to work with but i am not sure how to get it working.
Problem for me is that i have no idea how to use QueryPerformanceCounter
Then why do you want to implement it?
And the fact that you "googled for 6+ hours" means nothing! Someone could find the solution after googling for a couple of minutes, another one doesn't find it during the weeks!
The main problem with "googling" is you have to know what you are looking for!
PS: BTW, what is wrong for you with Timers?
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
If i know how to implement timers nothing is wrong.
If not then trying to make simple things work seems be very time consuming , il stick to tourials as it may teach more than watching google logo.
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
Well, again: did you read about Timers and its using in MSDN (I gave you a link in my previous post)? There are some code examples so you could very easy and fast implement it.
As for "QueryPerformanceFreqency and QueryPerformanceCounter": I don't use them (because I just don't need to!), so cannot give you any example. :cool:
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
yes i am trying to understand those, first i will need to undersatand terms then further.
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
{
LARGE_INTEGER freq; // ticks per second
LARGE_INTEGER startcount; //ticks at beginning
LARGE_INTEGER count; //all ticks
__int64 Time;
// get ticks per second
QueryPerformanceFrequency(&freq);
// count at start
QueryPerformanceCounter(&startcount);
// count for ending
QueryPerformanceCounter(&count);
// needed time
Time = t2.QuadPart+freq.QuadPart*3 //ticks at beginning+1sec*3
while(count => Time){ //time reaches higher than ticks at beginning+1sec*3
label1->Text = "aaaaaaaaa";
}
what is wrong with this code?
following errors appear:
1>c:\users\--\documents\visual studio 2010\projects\timer\timer\Form1.h(114): error C2065: 't2' : undeclared identifier
1>c:\users\--\documents\visual studio 2010\projects\timer\timer\Form1.h(114): error C2228: left of '.QuadPart' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\--\documents\visual studio 2010\projects\timer\timer\Form1.h(116): error C2143: syntax error : missing ';' before 'while'
1>c:\users\--\documents\visual studio 2010\projects\timer\timer\Form1.h(116): error C2059: syntax error : '>'
1>c:\users\--\documents\visual studio 2010\projects\timer\timer\Form1.h(116): error C2143: syntax error : missing ';' before '{'
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
Quote:
Originally Posted by
1248
Code:
{
LARGE_INTEGER freq; // ticks per second
LARGE_INTEGER startcount; //ticks at beginning
LARGE_INTEGER count; //all ticks
__int64 Time;
// get ticks per second
QueryPerformanceFrequency(&freq);
// count at start
QueryPerformanceCounter(&startcount);
// count for ending
QueryPerformanceCounter(&count);
// needed time
Time = t2.QuadPart+freq.QuadPart*3 //ticks at beginning+1sec*3
while(count => Time){ //time reaches higher than ticks at beginning+1sec*3
label1->Text = "aaaaaaaaa";
}
what is wrong with this code?
following errors appear:
1>c:\users\--\documents\visual studio 2010\projects\timer\timer\Form1.h(114): error C2065: 't2' : undeclared identifier
1>c:\users\--\documents\visual studio 2010\projects\timer\timer\Form1.h(114): error C2228: left of '.QuadPart' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\--\documents\visual studio 2010\projects\timer\timer\Form1.h(116): error C2143: syntax error : missing ';' before 'while'
1>c:\users\--\documents\visual studio 2010\projects\timer\timer\Form1.h(116): error C2059: syntax error : '>'
1>c:\users\--\documents\visual studio 2010\projects\timer\timer\Form1.h(116): error C2143: syntax error : missing ';' before '{'
- Please, use Code tags! Otherwise your code is not readable! :(
- The 't2' is not declared in the code snippet you have posted, So what do you expect? :confused:
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
Code:
{
LARGE_INTEGER freq; // ticks per second
LARGE_INTEGER time; //count+needed time
LARGE_INTEGER count; //all ticks
// get ticks per second
QueryPerformanceFrequency(&freq);
// count for ending
QueryPerformanceCounter(&count);
//ticks needed
time.QuadPart = (freq.QuadPart * 3) + count.QuadPart;
while (count.QuadPart > time.QuadPart){
label1->Text = "aaaaaaaaa";
}
}
Tryed to make it simple for myself and id like to ask few questions.
Do all numbers start to update constantly or only this line?
while (count.QuadPart > time.QuadPart)
if all then i am giving up to waste less time of others and self as i have too little understanding to learn to timers at microsoft page that is and thisone as well.
Is it possiblt to make it so that time.QuadPart = (freq.QuadPart * 3) + count.QuadPart; is calculated only 1 time?
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
Quote:
Originally Posted by
1248
Tryed to make it simple for myself
So did you succeed?
Quote:
Originally Posted by
1248
Do all numbers start to update constantly or only this line?
while (count.QuadPart > time.QuadPart)
It doesn't make much sense to discuss non-compilable code without any requiered definitions and initializations. :cool:
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
[QUOTE=VictorN;2064873]So did you succeed?
i belive code is now bit more simplified and it compiled and runs but if i toggle checkbox on user interface label 1 reamins label 1 not aaaaaaaaaa, i am hoping for aaaaaa to appear with delay.
i belive that it starts to calculate both values over and over or it only does it once and stops or does nothing at all.
What id like to learn is how to make 1 line repeat until it changes text to aaaaaaaa and other line calculate only once and use results for calculations on repeating line.
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
I'm glad your code now compiles and runs... :thumb:
However, we have no idea what your "user interface" is, nor know we anything about your checkbox, "aaaaaaaaaa" nad other labels.
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
Code:
#pragma once
#include <iostream>
#include <windows.h> // for Windows APIs
namespace timerfinal {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::CheckBox^ checkBox1;
private: System::Windows::Forms::Label^ label1;
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
//
// checkBox1
//
this->checkBox1->AutoSize = true;
this->checkBox1->Location = System::Drawing::Point(44, 12);
this->checkBox1->Name = L"checkBox1";
this->checkBox1->Size = System::Drawing::Size(80, 17);
this->checkBox1->TabIndex = 0;
this->checkBox1->Text = L"checkBox1";
this->checkBox1->UseVisualStyleBackColor = true;
this->checkBox1->CheckedChanged += gcnew System::EventHandler(this, &Form1::checkBox1_CheckedChanged);
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(41, 32);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(35, 13);
this->label1->TabIndex = 1;
this->label1->Text = L"label1";
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(158, 77);
this->Controls->Add(this->label1);
this->Controls->Add(this->checkBox1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void checkBox1_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
{
LARGE_INTEGER freq; // ticks per second
LARGE_INTEGER time; //count+needed time
LARGE_INTEGER count; //all ticks
// get ticks per second
QueryPerformanceFrequency(&freq);
// count for ending
QueryPerformanceCounter(&count);
//ticks needed
time.QuadPart = (freq.QuadPart*3) + count.QuadPart;
while (count.QuadPart >= time.QuadPart){
label1->Text = "aaaaaaaaa";
}
}
}
};
}
This compiles but i am not able to make a delay as i was hoping for because of too little understanding how to manipulate those numbers.
idea is taht by pressing checkbox1 it would make aaaaaaa appear with 3sec delay.
as far as i am able to understrand
QueryPerformanceFrequency should mean how many numbers per sec
QueryPerformanceCounter should be how many numbers have passed
Sleep() freezes all, tryed to understand others as well but too complicated to understand.
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
The code you've just posted is not a native VC++ code. It looks more like a managed C++ which is discussed in another forum. (Managed C++ and C++/CLI Discuss Managed C++ and .NET-specific questions related to C++)
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
Using QueryPerformanceCounter to insert a delay is a form of polling, and polling is evil.
Don't do it. And if you find examples based on GetTickCount or some other timer-style API, don't use them for the same reason.
Use timers, as suggested by VictorN.
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
What form of polling means in programming?
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
Quote:
Originally Posted by
1248
What form of polling means in programming?
See http://en.wikipedia.org/wiki/Polling_(computer_science)
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
So this code does nothing more tahn pollying with processor counter?
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
This code does nothing at all. Well, it obtains performance counter and performance frequency but then doesn't use them for any purpose. :cool:
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
Then all lines i added have no outcome so far, My idea was to learn a bit and then try to make a program that finds adresses by pointers in separate processes.
Then it would have delay control and ammount control and it would try to add for example 0.001 in every 500microsec to some adress in another process.
Also it could have button to add 1 more value and save option so all pointers would be stored.
How good skill it would take to make program i describe and how long average person obtains knowledge for that high skill?
Or are similar program already avalible that i describe?
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
Could you more clear explain what you mean by "program that finds adresses by pointers in separate processes" and why you think it is possible?
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
i ment that if pointers are directing to adresses and their values, then values would be chagned with small increasments and small delay would repeat this process.
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
Quote:
Originally Posted by
1248
i ment that if pointers are directing to adresses and their values, then values would be chagned with small increasments and small delay would repeat this process.
I didn't ask you about "delay"
I asked you
Quote:
Originally Posted by
VictorN
Could you more clear explain what you mean by "program that finds adresses by pointers in separate processes" and why you think it is possible?
What did you mean by "separate processes"?
-
Re: QueryPerformanceFreqency and QueryPerformanceCounter
In addition to what VictorN said ...
Quote:
Originally Posted by
1248
... try to make a program that finds adresses by pointers in separate processes ... and it would try to add for example 0.001 in every 500microsec to some adress in another process ... and save option so all pointers would be stored.
Reading and writing to/from addresses across different processes is very difficult. I would say the skill level is very high.
Mike