Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8060379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:58:32+00:00 2026-06-05T09:58:32+00:00

As I understand, the location of the virtual function pointer table in an object

  • 0

As I understand, the location of the virtual function pointer table in an object is compiler dependent.
Are there any pros/cons of placing this pointer at the beginning of the object vs at the end or vice-versa?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:58:34+00:00Added an answer on June 5, 2026 at 9:58 am

    The mere existence of a virtual function table is compiler dependent (but all compilers do), and the location is not mandated either… In all compilers of which I know the details, the vptr is stored in the beginning of the object. The reason is that it provides a uniform location. Consider a class hierarchy:

    struct base {
       T data;
       virtual void f();
    };
    struct derived : base {
       T1 data;
       virtual void g();
    };
    

    If the vptr was stored at the end of the object, then it would be after sizeof(T) bytes for an object of complete type base. Now when you have an object of complete type derived, the layout of the base sub object must be compatible with the layout of a complete base object, so the vptr would still have to be sizeof(T) bytes inside the object, which would be somewhere in the middle of the derived object (sizeof(T) from the beginning, sizeof(T1) before the end). So it would no longer be at the end of the object.

    Additionally, given a this pointer, a virtual call requires an indirection through the vtable, which basically is dereferencing the vptr, adding an offset and jumping to the memory location stored there. If the vptr was stored at the end of the object, for each virtual call there would be an extra addition to this before dereferencing the vptr.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public virtual IAsyncResult BeginProcessRequest(RequestContext context, AsyncCallback callback, object state) { return this.process.BeginInvoke(**ref context**, callback,
I understand virtual in the context of a member function, like virtual void frob()
I don't understand why an object is not removed from an NSMutableArray. This is
There is something i don't understand about the GAC files location ... When i
I understand the pros of using namespaces within the actual application layers but when
I understand that when adding a column to a table containing data in SQL
from what i read i understand that iPhone can determine your location using Wi-Fi.
I understand that the mapkit is used to show a device location in the
I don't understand why Cursor.Position is different from MouseEventArgs.Location , they should be the
I want to click a button and receive the current location, i understand that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.