Re: [Dev-C++] Sleep / for specified time delay :( ?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
From: Frederico M. <the...@ho...> - 2009-02-04 11:19:50
|
Hi Robert ;) Even though you are right, as those are the best aproches to the specified problem, thoses solutions have already been presented to the member(Sleep at least was). I find it improbable that the person who asked the original question hadn't already tried thoses solutions. In regarding with your rules, the Posix/SO especific function if far better than the implementation I presented as, I do understand that my implementation is wastefull. It spends to many cicles resolving the same equation to determine the elapsed time. But also I must say I am unaware of POSIX timer functions implemented in windows. If you know, please let me know, as it would be usefull for me as well. In relation to the original poster, I understood that the resulting binary application must run in win95/MS-DOS. If so, Sleep/SleepEx, the SO native functions are not usefull, because Sleep was implemented in win2000. Probably there are similar functions that I am unaware, that were implemented back in Win95 time, but I was unable to find information at this time. With that being said, however, my intention was not to present the snippet as the best aproche, only as one of many. But, in regarding with rule 1, I don't see why you cannot implement the same class, only modifying where is needed. ( Eg.: the function pair timeout ()/wait(). ) Thank you for the constructive criticism, nonetheless ^^ Frederico Marques> Date: Wed, 4 Feb 2009 05:45:39 -0500> From: ral...@gm...> To: the...@ho...> CC: dev...@li...> Subject: Re: [Dev-C++] Sleep / for specified time delay :( ?> > Please for the sake of yourself and the sanity of anyone who later may> need to debug or modify your code.> Please keep it simple and flexible by following two rules.> > 1) Create a customer Function, for example customerSleep(X) where X is> clock ticks, nano seconds, seconds, minutes, etc... what ever you> need.> 2a) Check the major standards for something that does what you need> and use that if at all possible in side your customer function.> 2b)I would suggest posix standard, sleep if you don't need a precise> delay, otherwise use the timeout feature of poll system call.> 3c)If for some reason neither of those work, use something for your OS.> > Following rule 1 will mean that you only need to make adjustments in> one place if you need to fix/change or port the delay to another> platform, or version, etc...> > Following the second rule will mean that it's more likely you won't> need to make a fixes/changes for bugs or ports.> > Hope this helps,> Robert> > On Wed, Feb 4, 2009 at 4:54 AM, Frederico Marques> <the...@ho...> wrote:> > Hey...> > (* first, for those u are C++ coders, i apologize, i'll be murdering C++> > below... if you have a faint heart, please look away! :P *)> > You can either use Sleep for windows... which works very well for most> > cases, or you can do something like :> >> > snippet :> > ---------------------------------------------------------> > #include <time.h>> >> > class DeltaTime {> > clock_t init;> > unsigned delta;> > public :> > DeltaTime( float sec = 1 ) { setDelta( sec ); }> > void setDelta( float sec ) { delta = CLK_TCK * sec; }> > void start() { init = clock(); }> > bool timeout() { return clock() - init >= delta; }> > void wait() { while (!timeout()) ; }> > }> > --------------------------------------------------------------------> >> > Usage :> > snippet :> > --------------------------------------------------------------------> >> > DeltaTime timer( 10 ) ;> > timer.start();> > timer.wait();> > --------------------------------------------------------------------> >> >> > Of course u can tweak it to make it more "easy" ... and, you can> > introduce some linked list of function pointers, that iterate while the code> > is in wait/timeout. Its "limitless" ^^.> >> >> > Frederico Marques> >> >> >> >> >> > ________________________________> > Date: Tue, 3 Feb 2009 22:06:55 +0200> > From: gx...@gm...> > To: dev...@li...> > Subject: [Dev-C++] Sleep / for specified time delay :( ?> >> > Hi,> >> > I want to make a delay/pause in C++, in Dev-C++... Does somebody know how to> > do that ? An example ?> >> > Thanks.> >> >> > ________________________________> > Diversão em dobro: compartilhe fotos enquanto conversa usando o Windows Live> > Messenger.> > ------------------------------------------------------------------------------> > Create and Deploy Rich Internet Apps outside the browser with> > Adobe(R)AIR(TM)> > software. With Adobe AIR, Ajax developers can use existing skills and code> > to> > build responsive, highly engaging applications that combine the power of> > local> > resources and data with the reach of the web. Download the Adobe AIR SDK and> > Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com> > _______________________________________________> > Dev-cpp-users mailing list> > Dev...@li...> > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users> >> >> > ------------------------------------------------------------------------------> Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)> software. With Adobe AIR, Ajax developers can use existing skills and code to> build responsive, highly engaging applications that combine the power of local> resources and data with the reach of the web. Download the Adobe AIR SDK and> Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com> _______________________________________________> Dev-cpp-users mailing list> Dev...@li...> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users _________________________________________________________________ Conheça o Windows Live Spaces, a rede de relacionamentos do Messenger! http://www.amigosdomessenger.com.br/ |