Re: [Dev-C++] differnece between system pause and cin.get()
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ho...> - 2003-02-18 02:18:42
|
-------Original Message-------=0D
=0D
From: Per Westermark=0D
Date: =D4=F1=DF=F4=E7, 18 =D6=E5=E2=F1=EF=F5=DC=F1=E9=EF=F2 2003 2:16:24 =
=F0=EC=0D
To: Ioannis Vranos=0D
Cc: dev...@li...=0D
Subject: Re: [Dev-C++] differnece between system pause and cin.get()=0D
=0D
> =3D=3D> It depends on how many things are written inside get(). However=
the=0D
> member function call is usually faster than a regular function call. Bu=
t i=0D
> do not think you should be so space/time concerned. :)=0D
=0D
For just about any type of programming, you may ignore any speed=0D
difference between member call and regular function call. For a new=0D
normal PC, we are talking nano-seconds. A member function call is normall=
y=0D
just a teeny bit slower, since it is a regular call with the extra=0D
requirement that it must send a 'this' pointer in registers or on the=0D
stack. If the member function is virtual, the member call must also=0D
perform the call indirect, by locating the call address in the VMT=0D
for the object. The only time a member call is as fast as a regular=0D
function call is if the member function is declared static - but then it=0D
is a regular function declared in the namespace of the class.=0D
=0D
-------------------------------------------------------------------------=
----
------------=0D
=3D=3D> We are getting lost in the details here, but for non-virtual memb=
er
functions passing *this does not imply any additional time cost in
comparison to regular functions. Also i do not think passing *this to
anything is required. Member functions do not have a regular address. The=
y
are usually called as an offset in an array. It is something like=0D
=0D
array[4](whatever)=0D
=0D
=0D
A regular friend function call for example would be implemented as someth=
ing
like:=0D
=0D
something(this, whatever). It's tough to say which is faster. So lets
consider them as of equal time cost and be in peace. :P=0D
=0D
However statistically speaking member functions tend to be small and inli=
ned
while regular functions manipulating objects not. But this can be disput=
ed
too. As i said, this shouldn't be taken under any consideration, that is =
the
time cost difference between cin.get() and system("pause"). Although syst=
em
has a function call time cost+a program invocation time cost+command.com/=
cmd
exe invocation time cost.=0D
-------------------------------------------------------------------------=
----
----------------=0D
=0D
=0D
=0D
What is important in this case is that system() is special. It is a=0D
request to start a new program 'PAUSE' and wait for that program to end,=0D
i.e. wait until you press a character.=0D
=0D
This is not the slightest problem for testing a debug-version of a=0D
program. However, in real production code, some care should be taken abou=
t=0D
the use of system() calls, because of the very large amount of work the o=
s=0D
has to do to perform the call. One call to system() might sound nice, but=
=0D
probably represents 100-10000 calls or more depending on what type of=0D
command that are put as argument. The OS has to start a new proces, with=0D
new stack... and might in some cases consume more memory and/or cpu=0D
time for the system() call than for the rest of the application.=0D
=0D
=3D=3D> Yes.=0D
=0D
=0D
Ioannis Vranos=0D
=0D
* Programming pages: http://www.noicys.freeurl.com=0D
* Alternative URL: http://run.to/noicys=20 |