473,395 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Timer Q

Hello,

I'm trying to find some existing (and simple if possible) timer queue
implementation. Does anybody know a simple skeleton to use as example?
I just need to send simple (relative) timeouts. Thought about some
possibilities but would prefer to use something already tested.

Thanksç
Dec 9 '07 #1
8 2330
si*********@gmail.com wrote:
I'm trying to find some existing (and simple if possible) timer queue
implementation. Does anybody know a simple skeleton to use as example?
I just need to send simple (relative) timeouts. Thought about some
possibilities but would prefer to use something already tested.
C++ language does not define "timers". There are no standard C++ means
to achieve what you need, I'm afraid. Did you perhaps mean to post to
the newsgroup dedicated to your OS?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 9 '07 #2
On Dec 10, 12:03 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
sip.addr...@gmail.com wrote:
I'm trying to find some existing (and simple if possible) timer queue
implementation. Does anybody know a simple skeleton to use as example?
I just need to send simple (relative) timeouts. Thought about some
possibilities but would prefer to use something already tested.

C++ language does not define "timers". There are no standard C++ means
to achieve what you need, I'm afraid. Did you perhaps mean to post to
the newsgroup dedicated to your OS?
Hi,

Thanks for your reply. I know I'm asking something that is not
completely standard, but I was looking for a portable implementation
of a timer queue. Ideally implemented using the stdlib. Of course,
there will be some os dependent parts but the algorithm itself should
be rather portable.

regards
Dec 9 '07 #3
si*********@gmail.com wrote:
On Dec 10, 12:03 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>sip.addr...@gmail.com wrote:
>>I'm trying to find some existing (and simple if possible) timer
queue implementation. Does anybody know a simple skeleton to use as
example? I just need to send simple (relative) timeouts. Thought
about some possibilities but would prefer to use something already
tested.

C++ language does not define "timers". There are no standard C++
means to achieve what you need, I'm afraid. Did you perhaps mean to
post to the newsgroup dedicated to your OS?

Hi,

Thanks for your reply. I know I'm asking something that is not
completely standard, but I was looking for a portable implementation
of a timer queue. Ideally implemented using the stdlib. Of course,
there will be some os dependent parts but the algorithm itself should
be rather portable.
If you're looking for the algorithm, this is not the right place either.

If the algorithm is the same whether it's written in C++ or, say, in
Java or Python, then .lang. newsgroups are not appropriate. Try asking
in 'comp.programming'. If you _have_ the algorithm but don't know how
to implement it in C++, then it *is* a language problem and you need to
start explaining what difficulty you have. You also have to explicitly
state that you have looked in other available sources, like Google, and
couldn't find anything.

This is not "give me your implementation of <blahin C++" newsgroup.
This is "I have this specific problem with C++ language construct" or
"Is this code looks OK from the Standard point of view" or "What is
partial template specialisation" newsgroup. Read the FAQ, read the
newsgroup archives, if this explanation is not enough.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 10 '07 #4
Victor Bazarov wrote:
si*********@gmail.com wrote:
>On Dec 10, 12:03 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>>sip.addr...@gmail.com wrote:
I'm trying to find some existing (and simple if possible) timer
queue implementation. Does anybody know a simple skeleton to use as
example? I just need to send simple (relative) timeouts. Thought
about some possibilities but would prefer to use something already
tested.
C++ language does not define "timers". There are no standard C++
means to achieve what you need, I'm afraid. Did you perhaps mean to
post to the newsgroup dedicated to your OS?
Hi,

Thanks for your reply. I know I'm asking something that is not
completely standard, but I was looking for a portable implementation
of a timer queue. Ideally implemented using the stdlib. Of course,
there will be some os dependent parts but the algorithm itself should
be rather portable.

If you're looking for the algorithm, this is not the right place either.

If the algorithm is the same whether it's written in C++ or, say, in
Java or Python, then .lang. newsgroups are not appropriate. Try asking
in 'comp.programming'. If you _have_ the algorithm but don't know how
to implement it in C++, then it *is* a language problem and you need to
start explaining what difficulty you have. You also have to explicitly
state that you have looked in other available sources, like Google, and
couldn't find anything.

This is not "give me your implementation of <blahin C++" newsgroup.
This is "I have this specific problem with C++ language construct" or
"Is this code looks OK from the Standard point of view" or "What is
partial template specialisation" newsgroup. Read the FAQ, read the
newsgroup archives, if this explanation is not enough.
I'm as much of an on-topic freak as the next guy, Victor, but I think in
this case, we're OK. He's admitted that the timer stuff is OS specific,
but looking for a C++ mechanism for maintaining the queue of OS specific
stuff.

Anyways, sip_address, I'd define a class of timer objects, and then use
a std::priority_queue() to maintain them. Note that if you need to
delete an element mid-queue (kill a timer before it's time), then you
should derive from std::priority_queue -- PRIVATELY -- to gain access to
the underlying (protected) container.
Dec 10 '07 #5
On 12/10/2007 9:18 PM, red floyd wrote:
[...]
Anyways, sip_address, I'd define a class of timer objects, and then use
a std::priority_queue() to maintain them. Note that if you need to
delete an element mid-queue (kill a timer before it's time), then you
should derive from std::priority_queue -- PRIVATELY -- to gain access to
the underlying (protected) container.
Isn't std::priority_queue just a wrapper around a std::vector and
the heap functions (make_heap, push_heap, pop_heap) ?
Doesn't deleting an element 'mid-queue' invalidate the heap ?

Any comments ?

S.
--
Stefan Naewe stefan dot naewe at atlas-elektronik dot com
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
Dec 11 '07 #6
Stefan Naewe wrote:
On 12/10/2007 9:18 PM, red floyd wrote:
>[...]
Anyways, sip_address, I'd define a class of timer objects, and then use
a std::priority_queue() to maintain them. Note that if you need to
delete an element mid-queue (kill a timer before it's time), then you
should derive from std::priority_queue -- PRIVATELY -- to gain access to
the underlying (protected) container.

Isn't std::priority_queue just a wrapper around a std::vector and
the heap functions (make_heap, push_heap, pop_heap) ?
Doesn't deleting an element 'mid-queue' invalidate the heap ?
That's why you derive, so that if you delete from the middle, you can
call make_heap on the embedded container. Note that the container is a
protected member of the priority_queue.
E.g. (pseudocode follows):

class timer_queue : private std::priority_queue()
{
public:

using std::priority_queue::{methods};
void delete_timer(timer_id);
};

void timer_queue::delete_timer(timer_id id)
{
// find id in container
// remove from container
// call make_heap on container
}
Dec 11 '07 #7
On Dec 10, 3:18 pm, red floyd <no.s...@here.dudewrote:
Victor Bazarov wrote:
sip.addr...@gmail.com wrote:
On Dec 10, 12:03 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
sip.addr...@gmail.com wrote:
I'm trying to find some existing (and simple if possible) timer
queue implementation. Does anybody know a simple skeleton to use as
example? I just need to send simple (relative) timeouts. Thought
about some possibilities but would prefer to use something already
tested.
C++ language does not define "timers". There are no standard C++
means to achieve what you need, I'm afraid. Did you perhaps mean to
post to the newsgroup dedicated to your OS?
Hi,
Thanks for your reply. I know I'm asking something that is not
completely standard, but I was looking for a portable implementation
of a timer queue. Ideally implemented using the stdlib. Of course,
there will be some os dependent parts but the algorithm itself should
be rather portable.
If you're looking for the algorithm, this is not the right place either.
If the algorithm is the same whether it's written in C++ or, say, in
Java or Python, then .lang. newsgroups are not appropriate. Try asking
in 'comp.programming'. If you _have_ the algorithm but don't know how
to implement it in C++, then it *is* a language problem and you need to
start explaining what difficulty you have. You also have to explicitly
state that you have looked in other available sources, like Google, and
couldn't find anything.
This is not "give me your implementation of <blahin C++" newsgroup.
This is "I have this specific problem with C++ language construct" or
"Is this code looks OK from the Standard point of view" or "What is
partial template specialisation" newsgroup. Read the FAQ, read the
newsgroup archives, if this explanation is not enough.

I'm as much of an on-topic freak as the next guy, Victor, but I think in
this case, we're OK. He's admitted that the timer stuff is OS specific,
but looking for a C++ mechanism for maintaining the queue of OS specific
stuff.

Anyways, sip_address, I'd define a class of timer objects, and then use
a std::priority_queue() to maintain them. Note that if you need to
delete an element mid-queue (kill a timer before it's time), then you
should derive from std::priority_queue -- PRIVATELY -- to gain access to
the underlying (protected) container.- Hide quoted text -

- Show quoted text -
For the underlying implementation of the timer object check out asio.
It's a C++ cross-platform socket wrapper that includes timers. I'm
not sure if it's made it's way into boost yet.
Dec 11 '07 #8
On Dec 10, 9:18 pm, red floyd <no.s...@here.dudewrote:

[...]
Anyways, sip_address, I'd define a class of timer objects, and
then use a std::priority_queue() to maintain them. Note that
if you need to delete an element mid-queue (kill a timer
before it's time), then you should derive from
std::priority_queue -- PRIVATELY -- to gain access to the
underlying (protected) container.
What's wrong with using std::set or std::multi_set, sorted by
time, and using std::set::iterator as the handle for the timer
queue entry (to be able to delete it). Alternatively, you could
simply use Timer* as the handle---when you wanted to delete,
std::supports erase by key, so deleting *handle will do the
trick. (In this case, you'd probably want to use std::set, with
each timer element having a unique identifier, which would serve
as a secondary key, to ensure that erase only affects a single
element. Any other arrangement which allows uniquely
indentifying the entries can be made work, however.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Dec 12 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on...
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
9
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null;...
7
by: Grahmmer | last post by:
I have a few timers that are added to a form at runtime. I can handle the event fine, but I cannot identify which timer fired. Is there a way to do this? Timer Creation: -------------...
2
by: John David Thornton | last post by:
I've got a Windows Service class, and I put a System.Threading.Timer, and I've coded it as shown below. However, when I install the service and then start it in MMC, I get a peculiar message: ...
12
by: Gina_Marano | last post by:
I have created an array of timers (1-n). At first I just created windows form timers but I read that system timers are better for background work. The timers will just be monitoring different...
8
by: KnighT | last post by:
I have a .net service that runs a System.Threading.Timer. The delegate points to the function that the service should execute when the timer elapses. Problem: The timer is not ticking. I have...
8
by: =?Utf-8?B?RGF2ZSBCb29rZXI=?= | last post by:
I have a Timer that I set to go off once a day, but it frequently fails! In order to debug I would like to be able to check, at any moment, whether the Timer is enabled and when it will next...
11
by: Hotrod2000 | last post by:
I'm quite new to programming but I'm having problems getting a timer to work in visual studio.net I've created a timer on a form, enabled it and then typed the following code (from the mdsn...
16
by: Peter Oliphant | last post by:
Note that although this involves SAPI, it is more a question about Timers and event handlers. I wrote a Speech Recognize handler (SAPI), and put some code in it to enable a Timer. It would not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.