By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,233 Members | 1,972 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,233 IT Pros & Developers. It's quick & easy.

Jumps through a program

P: n/a
Technically, which is more efficient, to jump to the 100th function of one
class or to jump to the 100th class? Class would be through inheritance as
an object. Is there a comment on embeded objects to this subject too?

Regards,
Jeffrey Baker
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Jeffrey Baker wrote:
Technically, which is more efficient, to jump to the 100th function of
one class or to jump to the 100th class?


What do you mean by "jump to the 100th function" or jumping to a class?
Jul 22 '05 #2

P: n/a
Jeffrey Baker wrote:
Technically, which is more efficient, to jump to the 100th function of one
class or to jump to the 100th class? Class would be through inheritance as
an object. Is there a comment on embeded objects to this subject too?

Regards,
Jeffrey Baker


If a class has 100 methods (member functions), executing any one of them
is of order O(1) (unless they are virtual). The compiler will know the
location of the function and supply code to call the function. Check
your assembly code.

If you have 100 individual classes then use a method from one of the
classes (i.e. class_99.method()) this would be of order O(1). Again,
the compiler will know the location of the function and insert the
appropriate calling code.

Some concepts that may add another layer of indirection:
1. inheritance
2. virtual methods
3. pointers to methods or functions.

Inheritance may add another layer of indirection if the compiler
must supply run-time code to find the function. Otherwise, the
function is at a known location and the order is O(1).

Virtual methods require some kind of run-time evaluation to
find the correct method to execute. Some compilers speed up
the process by using a table, although that isn't required.

Pointers to methods or functions require that the compiler
issue code to dereference the pointer before executing
the function. This is a minimum of 1 level of indirection.

I don't understand what your definition of "embeded objects"[sic]
is. I work on embedded systems and my understanding may be
different than yours. Please clarify.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #3

P: n/a

"Thomas Matthews" <Th**********************@sbcglobal.net> wrote in message
news:hD******************@newssvr31.news.prodigy.c om...
Jeffrey Baker wrote:
Technically, which is more efficient, to jump to the 100th function of one class or to jump to the 100th class? Class would be through inheritance as an object. Is there a comment on embeded objects to this subject too?

Regards,
Jeffrey Baker
If a class has 100 methods (member functions), executing any one of them
is of order O(1) (unless they are virtual). The compiler will know the
location of the function and supply code to call the function. Check
your assembly code.

If you have 100 individual classes then use a method from one of the
classes (i.e. class_99.method()) this would be of order O(1). Again,
the compiler will know the location of the function and insert the
appropriate calling code.

Some concepts that may add another layer of indirection:
1. inheritance
2. virtual methods
3. pointers to methods or functions.

Inheritance may add another layer of indirection if the compiler
must supply run-time code to find the function. Otherwise, the
function is at a known location and the order is O(1).

Virtual methods require some kind of run-time evaluation to
find the correct method to execute. Some compilers speed up
the process by using a table, although that isn't required.

Pointers to methods or functions require that the compiler
issue code to dereference the pointer before executing
the function. This is a minimum of 1 level of indirection.

I don't understand what your definition of "embeded objects"[sic]
is. I work on embedded systems and my understanding may be
different than yours. Please clarify.

Actually I don't know what I meant. I think I was thinking in terms of
another language in terms of basic way back when. I actually answered my
question after my sent post. Been away from C++ for a while. Thanks for
waking me up.
--
It is better to post code then to never tried.
Jeffrey Baker
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.