Boost logo

Boost :

From: Jesse Jones (jesjones_at_[hidden])
Date: 2001-05-09 05:35:09

> > You seem to be talking about the RAII idiom which doesn't seem to
>> really make sense for timers. Neither the Mac (with Carbon Event
>> timers) nor Windows (with WM_TIMER) are going to support creating a
>> timer on the stack inside a function which is where RAII shines. Not
>> that trying to do that makes any sense to me...
>I'll have to disagree on two grounds.
>1. RAII is *not* just for stack variables, but for all objects which have a
>clearly defined lifetime. If you want to register a (non-static) member
>function of object A as a timer callback, you need to make sure that this
>timer does not outlive object A. You can do this by unregistering the timer
>callback in A's destructor, but this is error-prone. (Consider that A's
>destructor never gets called if A's constructor throws an exception, which
>might happen after the callback is already registered). RAII really is the
>superior idiom here.

I can't really argue with that. Good summary :-)

>2. Even with an event-based timer architecture, creating the timer on the
>stack inside a function makes sense so long as the function contains an
>event loop. There is really no reason to limit yourself to a single event
>loop in 'main'/'WinMain'.

That's true, but that's an awfully unusual case, especially in client code.

   -- Jesse

Boost list run by bdawes at, gregod at, cpdaniel at, john at