[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: c++ question: code duplication across classes
From:       Benoit Jacob <jacob () math ! jussieu ! fr>
Date:       2006-09-20 8:16:27
Message-ID: Pine.LNX.4.64.0609201012160.7064 () galois2 ! math ! jussieu ! fr
[Download RAW message or body]

OK, thanks a lot. So virtual is clearly a no-go for me. I'll stick to my 
idea of having common template functions directly calling getters like 
T::width() and T::height(), and do no inheritance, no virtual stuff.

Benoit

On Wed, 20 Sep 2006, Thiago Macieira wrote:
> The overhead of a virtual method is an indirect jump (instead of a direct
> one). This used to be a problem because it would throw off all prediction
> done in modern CPUs, because they didn't predict indirect branches. I
> don't know if that's still true.
>
> So, if you can, avoid virtuals if speed is an issue.
>
>> or only some
>> memory taken per instantiation? Also : the vtable doesn't inflate the
>> sizeof of the class, right ? (well i guess the latter question is
>> stupid but I'd rather be sure :) )
>
> For a simple class,
> sizeof(vtable) = k + sizeof (void (*)()) * N
>
> where k is a constant and N is the number of virtual functions. Generally,
> k isn't larger than 8-16 bytes. This can get a lot more complex if
> secondary virtual tables are necessary (multiple inheritance, virtual
> inheritance), but isn't the case here.
>
> In the case of a template class, you have to remember that the virtual
> table's instantiation causes the instantiation of ALL virtual functions
> in each DSO module that used them.
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic