Re: [Dev-C++] differnece between system pause and cin.get()
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2003-02-18 00:17:44
|
On Tue, 18 Feb 2003, Ioannis Vranos wrote: > -------Original Message------- > > From: Catsquotl > Date: =C4=E5=F5=F4=DD=F1=E1, 17 =D6=E5=E2=F1=EF=F5=DC=F1=E9=EF=F2 2003 2:= 21:19 =EC=EC > To: dev...@li... > Subject: [Dev-C++] differnece between system pause and cin.get() > > Hello, > > Obviously there are quite a lot of differences between the two. > However since I am new to c++ and pragramming all together i was wonderin= g > why cin.get() > works sometimes to pauze the system after a programm and sometimes it won= `t. > > =3D=3D> Because one or more '\n' has remain in the stream from previous c= in > use(s). > > > It seems to me that cin.get() before return 0; > would use less memory than system pause. > > =3D=3D> It depends on how many things are written inside get(). However t= he > member function call is usually faster than a regular function call. But = i > do not think you should be so space/time concerned. :) For just about any type of programming, you may ignore any speed difference between member call and regular function call. For a new normal PC, we are talking nano-seconds. A member function call is normally just a teeny bit slower, since it is a regular call with the extra requirement that it must send a 'this' pointer in registers or on the stack. If the member function is virtual, the member call must also perform the call indirect, by locating the call address in the VMT for the object. The only time a member call is as fast as a regular function call is if the member function is declared static - but then it is a regular function declared in the namespace of the class. What is important in this case is that system() is special. It is a request to start a new program 'PAUSE' and wait for that program to end, i.e. wait until you press a character. This is not the slightest problem for testing a debug-version of a program. However, in real production code, some care should be taken about the use of system() calls, because of the very large amount of work the os has to do to perform the call. One call to system() might sound nice, but probably represents 100-10000 calls or more depending on what type of command that are put as argument. The OS has to start a new proces, with new stack... and might in some cases consume more memory and/or cpu time for the system() call than for the rest of the application. /Per W > > Ioannis Vranos > > * Programming pages: http://www.noicys.freeurl.com > * Alternative URL: http://run.to/noicys |