This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Using virtual classes overhead

Other Parts Discussed in Thread: CC3200

Hi all,

Me and my team are using cc3200 on our project.

We would like to use interfaces in our code for better encapsulation and for future testing interfaces.

We are using TI v16.9.0 L.T.S compiler. 

Does anyone know what are the overheads (memory (vtables) and runtime) of using interfaces/virtual classes in our code base.

Itay.

  • Hi tokyo tokyo,

    I believe that this question is not specific to CC3200, but instead to the ARM compiler. I'm going to move this question to the TI C/C++ Compiler forum.

    Best Regards,
    Ben
  • Thanks,

    Can you please keep me notified with the new thread.

    Itay
  • First, some background.  Questions of efficiency regarding C++ are not specific to ARM compilers, or even TI ARM compilers.  These questions, and their answers, are the same, with only small differences that come from the underlying CPU architecture or compiler vendor.  This is good news.  Because that means the large amount of existing books, tutorials, etc. on C++ efficiency are very useful here.  Please take full advantage of them.

    tokyo tokyo said:
    Does anyone know what are the overheads (memory (vtables) and runtime) of using interfaces/virtual classes in our code base.

    Speaking generally, for a class that has virtual functions, the overhead is one virtual table (shared by all objects) and one pointer to the virtual table (per object).

    This is overhead in comparison to a class that has no virtual functions.  Which is to say a class that has less capability.  That raises the question of whether this is a fair comparison.  Suppose you somehow create your own custom solution that has the same capability.  What is the overhead of virtual functions compared with this custom solution with similar capability?  That overhead is probably zero.

    Thanks and regards,

    -George

  • George is correct that comparing a virtual function call to a non-virtual function call is an unfair comparison because the virtual call feature a significantly different operation that you just wouldn't use if it weren't necessary. That said, a virtual function call is necessarily slower than a non-virtual call, primarily because the function address must be fetched from memory. Use virtual functions only when you need them, but do go ahead and use them when appropriate.
  • Thanks for the detailed answers.

    Itay