Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtual Table layout in memory?

Tags:

People also ask

Where are virtual tables stored?

Vtables themselves are generally stored in the static data segment, as they are class-specific (vs. object-specific).

How does a vtable work?

For every class that contains virtual functions, the compiler constructs a virtual table, a.k.a vtable. The vtable contains an entry for each virtual function accessible by the class and stores a pointer to its definition. Only the most specific function definition callable by the class is stored in the vtable.

What is VPTR and vtable in C++?

The compiler places the addresses of the virtual functions for that particular class in the VTABLE. In each class with virtual functions, it secretly places a pointer, called the vpointer (abbreviated as VPTR), which points to the VTABLE for that object.

How many virtual tables are created?

Basically, 2. One for class A , one for class B (vftables) and 2 vfptrs, one for a1 and one for b1 . However, this is not standard mandated, so you could as well have none. (usually implementations use vftables, but its not mandated.


how are virtual tables stored in memory? their layout?

e.g.

class A{
    public:
         virtual void doSomeWork();
};

class B : public A{
    public:
         virtual void doSomeWork();
};

How will be the layout of virtual tables of class A and class B in memory?