Talei
21st July 2011, 22:32
Hello.
I don't know if this is right place to write this, so pardon me if it's not.
Problem: perform many operation (like 12k++) one after another (to shorten this time I want to execute each operation as soon as previouse is finished). So in nutshell the same set of functions are performed many times on different set of data.
My implementation:
Currently I do it "wrong way" and not so wrong (maybe a right?) way.
Wrong way using signal/slot mechanism (wrong in terms of logical implementation, not in code itself) - pseudo code:
void myProgrma::myProgrma(){
connect( this, SIGNAL( jobDone() ), this, SLOT(controlSLOT()));
myProgrma();
}
void myProgrma::controlSLOT()
{
if(jobIsDone)
return;
else
doJobSLOT()
}
void myProgrma::doJobSLOT()
{
//do job here
emit jobDone();
}
As you can see there is one flaw with this implementation with is that for many, like 64k++, jobs (or less depending on what is in doJobSLOT() ) this will fail (AFAIK - please elaborate about this, if my thinking is wrong) due to the exceeding job queue stack size - due to not returning from slots that's leads to queue being full and thus error.
I found out, on my trails and errors path, that using only signal/slot mechanism is a loot more faster then using QTimer solution (QTimer is about 6+ times slower). I guess that's due to the all those checks and overhead of the QTimer class. Basically I'm looking for fastest i9mplementation of this problem.
I know that I can implement solution for this problem using QTimer and timeout() signal, but my question is:
Is there any other way to implement "while/for" loop behaviour (basically above example does those loops) (or AFAIK so called Observer Pattern) in Qt?
Thank you for any advice on this mater.
Best regards.
PS. in pseudo code "jobIsDone" is bool to check if there is any pending job to be done.
I don't know if this is right place to write this, so pardon me if it's not.
Problem: perform many operation (like 12k++) one after another (to shorten this time I want to execute each operation as soon as previouse is finished). So in nutshell the same set of functions are performed many times on different set of data.
My implementation:
Currently I do it "wrong way" and not so wrong (maybe a right?) way.
Wrong way using signal/slot mechanism (wrong in terms of logical implementation, not in code itself) - pseudo code:
void myProgrma::myProgrma(){
connect( this, SIGNAL( jobDone() ), this, SLOT(controlSLOT()));
myProgrma();
}
void myProgrma::controlSLOT()
{
if(jobIsDone)
return;
else
doJobSLOT()
}
void myProgrma::doJobSLOT()
{
//do job here
emit jobDone();
}
As you can see there is one flaw with this implementation with is that for many, like 64k++, jobs (or less depending on what is in doJobSLOT() ) this will fail (AFAIK - please elaborate about this, if my thinking is wrong) due to the exceeding job queue stack size - due to not returning from slots that's leads to queue being full and thus error.
I found out, on my trails and errors path, that using only signal/slot mechanism is a loot more faster then using QTimer solution (QTimer is about 6+ times slower). I guess that's due to the all those checks and overhead of the QTimer class. Basically I'm looking for fastest i9mplementation of this problem.
I know that I can implement solution for this problem using QTimer and timeout() signal, but my question is:
Is there any other way to implement "while/for" loop behaviour (basically above example does those loops) (or AFAIK so called Observer Pattern) in Qt?
Thank you for any advice on this mater.
Best regards.
PS. in pseudo code "jobIsDone" is bool to check if there is any pending job to be done.