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 7590131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:19:49+00:00 2026-05-30T20:19:49+00:00

Take these two classes for example (C++) class B1 { public: }; class B2

  • 0

Take these two classes for example (C++)

class B1 {
public:

};

class B2 {
public:
  void f0 () {}
  void f1 () {}
};

How much bigger would class B2 be in memory Vs B1

I feel like it’s one of two answers:

A single 4 byte int pointer on 32 bit systems PER method.

Or something similar to what happens with Virtual Method Tables http://en.wikipedia.org/wiki/Virtual_method_table

Where there would be one 4 byte int pointer that points to a table for each class so it can look up it’s methods, which would make sense, but I don’t know if this happens for non-virtual methods.

Thanks.

Edit : Thanks for all of the awesome and quick replies 🙂 (Also marked answer)

  • 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-05-30T20:19:50+00:00Added an answer on May 30, 2026 at 8:19 pm

    None.

    Non-virtual methods don’t increase a class’s size.

    As for virtual methods, only the first one added to a class will increase its size, all subsequent ones do not.

    The fact that it’s inline or not also doesn’t affect the class size.

    The reason for this is that extra memory is not needed. Just imagine if all instances of all classes held pointers to all methods in the class and all parent classes. That would be a huge waste of memory.

    B2 b;
    b.f0();
    

    the compiler can simply generate code to call B2::f0(). The this pointer is passed as an under-the-hood parameter so that the method know on which instance of the class to operate.

    For a simple test:

    class B1 {
    public:
    
    };
    
    class B2 {
    public:
      void f0 () {}
      void f1 () {}
    };
    
    //...
    assert( sizeof(B1) == sizeof(B2) );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take these two Java classes: class User { final Inventory inventory; User (Inventory inv)
Let's say I have these classes: public class BaseMapClass<T1, T2> { protected T1 Thing1;
I am getting a little confused and need some help please. Take these two
I have a class that currently has several methods that take integer parameters. These
This is a follow-up question to this one . Take a look at these
Is there a shortcut to take a base class and transform it into one
Objective-C has no namespaces; it's much like C, everything is within one global namespace.
Take a look at this example, and notice the outputs indicated. <?php class Mommy
I have two classes, namely User & UserProfile User contains(few attributes like):- userId loginId
In my program I have two classes, one called GlassPiece, and one called TrackerChip.

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.