Jumps through a program

J

Jeffrey Baker

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
 
R

Rolf Magnus

Jeffrey said:
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?
 
T

Thomas Matthews

Jeffrey said:
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
 
J

Jeffrey Baker

Thomas Matthews said:
Jeffrey said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top