Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size of virtual pointer-C++

What is the size of virtual pointer(VPTR) for a virtual table in C++? Also this is not a homework question...just a question that came to my mind while I was reading a C++ book.

like image 649
Light_handle Avatar asked Oct 21 '09 23:10

Light_handle


People also ask

What is the size of Vtable?

The size of an object is determined by its member variables and the padding and the presence of virtual functions or bases. @In silico: right, For class C, does it insert f3 in the both vtables inherited from A, B? If not, C should have one more vtable making its size 12 bytes.

What is virtual function size?

A virtual function is a pointer with 8 bytes.

What is the size of class pointer?

The size of a pointer in C/C++ is not fixed. It depends upon different issues like Operating system, CPU architecture etc. Usually it depends upon the word size of underlying processor for example for a 32 bit computer the pointer size can be 4 bytes for a 64 bit computer the pointer size can be 8 bytes.

How does virtual function affect the size of an object?

The use of virtual functions increases the size of an object, typically by the size of a pointer to the vtable. This may be an issue if you wish to create a small object that requires a very large number of instances.


1 Answers

An excellent article related to this topic is Member Function Pointers and the Fastest Possible C++ Delegates. This article delves deeply into the implementation of member function pointers for many different compilers. This article talks about all the nuances of vtable pointers particularly in light of multiple (and virtual) inheritance.

like image 148
Greg Hewgill Avatar answered Sep 30 '22 16:09

Greg Hewgill