Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c++ Subject: Re: Event handler in c++ Date: Wed, 15 Feb 2012 07:17:43 +1300 Lines: 55 Message-ID: <9pvmq7FaapU1@mid.individual.net> References: <707d72e5-d35d-412c-bac8-efe54ad365cb@z12g2000yqm.googlegroups.com> <9o2teeFeiaU1@mid.individual.net> <64c600db-1c76-44c3-9b64-41723d68754a@s7g2000vby.googlegroups.com> <66228237-d278-44c6-a491-471b9073dfa9@hb4g2000vbb.googlegroups.com> <30919923.35.1329214493307.JavaMail.geo-discussion-forums@pbbmr9> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net MGHx+Nk9i/oHMDWoH0js0QtL2i5YSqHArNmOG9jC3LEsxnRkG2 Cancel-Lock: sha1:uOpU30MkrHEfgvPcaodojfC+y0w= User-Agent: Mozilla/5.0 (X11; SunOS i86pc; rv:6.0.2) Gecko/20111003 Thunderbird/6.0.2 In-Reply-To: <30919923.35.1329214493307.JavaMail.geo-discussion-forums@pbbmr9> Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:14045 On 02/14/12 11:14 PM, 88888 Dihedral wrote: > 在 2012年2月13日星期一UTC+8下午7时52分44秒,Robin Tucker写道: >> I'm using a templated method to describe, dispatch and handle events >> in an intuitive manner. For example, describing an event can be done >> with something like this: >> >> Event, double, double, double)> >> MyEvent; >> >> , for an event that takes 4 parameters (the "sender" and three >> doubles). The handler looks like this: >> >> void OnEventHandler(std::shared_ptr sender, double x, >> double y, double z) >> { >> // Handle the event. >> } >> >> And the event is dispatched in the following intuitive way: >> >> MyEvent(shared_from_this(), 3, 2, 1); >> >> It's type-safe and you can dispatch any number of parameters (up to 9 >> actually, in the absence of variadic templates in VS2010!). Anyway the >> code and blog about it can be found here: >> >> http://drrobsjournal.blogspot.com/ >> >> I hope this is useful to someone. > > C++ is not very good to be usd as a language to > write device drives to be called by the OS. Yes it is, you just have to provide the OS hooks as extern "C" functions. > People working on the linux kernal talked about this > problem for so long. They are somewhat bigoted. > Unless functions in the C++ container and template libraries are incorporated into the OS kernal library > or system shared linked libraries, otherwise C++ compiled programs are too fat in the heap, too. "too fat in the heap" ? In kernel space you have two choices: 1) Use C++ as a better C and avoid the parts that require runtime support. 2) Use a statically linked run time library. I use one where resources are tight and 2 where they are not. -- Ian Collins