Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Timer Q

Reply
Thread Tools

Timer Q

 
 
sip.address@gmail.com
Guest
Posts: n/a
 
      12-09-2007
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ç
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      12-09-2007
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


 
Reply With Quote
 
 
 
 
sip.address@gmail.com
Guest
Posts: n/a
 
      12-09-2007
On Dec 10, 12:03 am, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
> 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
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      12-10-2007
wrote:
> On Dec 10, 12:03 am, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
>> 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 <blah> in 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


 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      12-10-2007
Victor Bazarov wrote:
> wrote:
>> On Dec 10, 12:03 am, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
>>> 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 <blah> in 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:riority_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:riority_queue -- PRIVATELY -- to gain access to
the underlying (protected) container.
 
Reply With Quote
 
Stefan Naewe
Guest
Posts: n/a
 
      12-11-2007
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:riority_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:riority_queue -- PRIVATELY -- to gain access to
> the underlying (protected) container.


Isn't std:riority_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
 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      12-11-2007
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:riority_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:riority_queue -- PRIVATELY -- to gain access to
>> the underlying (protected) container.

>
> Isn't std:riority_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:riority_queue()
{
public:

using std:riority_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
}
 
Reply With Quote
 
AnonMail2005@gmail.com
Guest
Posts: n/a
 
      12-11-2007
On Dec 10, 3:18 pm, red floyd <no.s...@here.dude> wrote:
> Victor Bazarov wrote:
> > sip.addr...@gmail.com wrote:
> >> On Dec 10, 12:03 am, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
> >>> 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 <blah> in 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:riority_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:riority_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.
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      12-12-2007
On Dec 10, 9:18 pm, red floyd <no.s...@here.dude> wrote:

[...]
> Anyways, sip_address, I'd define a class of timer objects, and
> then use a std:riority_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:riority_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:
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I know about the shutdown timer, is there a "switch on" timer... Mal Carter Computer Support 3 01-12-2008 01:58 AM
page timer, or redirect timer Simon ASP .Net 1 11-04-2005 07:14 PM
System.Timers.Timer/System.Threading.Timer Not Firing At All on Dev Server james.e.coleman@gmail.com ASP .Net 1 02-22-2005 09:41 PM
old timer on net but Mozilla newbie carlton hunter Firefox 1 01-31-2004 04:53 AM
System.Timers.Timer vs. System.Threading.Timer Kelsang Wangchuk ASP .Net 0 07-31-2003 04:28 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57