Overhead base class versus derived class method invocation

Q

question

I want to know incase there is any performance difference or overhead
in calling a base class method and a derived class method.

Basically I am talking about simple method that is not overridden nor
virtual. If I declare a method in the base class say M1() and another
in derived class M2(). Then I make a derived class object derived. I
then invoke these:

derved.M1()
derived.M2()

What difference would it be.

Also does the size of the class object increase with more method
members in the class. Incase I add methods to the base class would it
increase the size of the derived class also.

Thankx in advance to you all.
 
N

Nicholas Paldino [.NET/C# MVP]

Basically, nothing. There would be a lookup in the method table for the
object, and then it would be executed.

Honestly, it's not even something to be concerned about.

The size of the ^type^ will increase with each member in the class, as
well as any derived classes. However, you ^REALLY^ shouldn't worry about
this. Unless you had hundreds of members though. However, at this point, I
wouldn't be worried about performance (it still wouldn't be an issue), but
because of design (one type with that many members is excessive, and poorly
designed).

Hope this helps.
 

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

Top