I wasn't talking about the value-added algorithms.  I was talking about
the underlying features introduced by the language that may,
inadvertently, affect performance.

For, example, there is no string type in C, so pointers to character (or
character arrays) are used.  In C++ with MFC you have the CString class
that adds a string "type".

In C, you may have code like this:
 char * psz;
 psz = "this is some text";
where in C++ you may have code like this:
 CString str;
 str = CString("str");

While both perform the same logic the C++ version is much less efficient.
In C, it's a simple integer assignment.  In C++, a temporary object is
allocated, a integer value is pushed on the stack, a method (c'tor) is
called), a method (operator= or default code) is called, and finally
another method is called (d'tor), not including all the stack pushing and
popping.

This doesn't mean C++ is less efficient; it just means that it allows
programmers that are familiar with the syntax and not the performance
consequences to write inefficient code easier.

In all fairness, though, you could write something inefficient in C:
char * psz = strdup("text");

Optimizing the C++ to avoid this inefficiency would not translate to the C
code.

http://www.peterRitchie.com/

On Mon, 11 Jul 2005 13:49:44 -0500, Vijay Mahadevan
<[EMAIL PROTECTED]> wrote:

>I have to disagree on the statement that any OO language can perform
>equally and as efficient as a procedural language like C. Any
>indirection in the execution of a procedural code is an overhead and
>it can never be compensated with a better logic or algorithm ( because
>you could write the same efficient algo in the procedural language too
>! ). If your logic is not the same in different languages, then the
>benchmark or comparison is meaningless.
>
>All higher level languages work on the principle of indirection,
>thereby creating another abstraction in the execution of the code.
>There could be several reasons and uses that come out of that but the
>speed of execution will be definitely lower. 10 calls instead of 50
>calls on the same cpu is going to be lesser anytime !
>

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to