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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:13:52+00:00 2026-05-18T10:13:52+00:00

I was reading about Empty Base Optimization(EBO). While reading, the following questions popped up

  • 0

I was reading about Empty Base Optimization(EBO). While reading, the following questions popped up in my mind:

  1. What is the point of using Empty class as base class when it contributes nothing to the derived classes (neither functionality-wise, nor data-wise)?

  2. In this article, I read this:

//S is empty
class struct T : S
{
      int x;
};

[…]

Notice that we didn’t lose any data or
code accuracy: when you create a
standalone object of type S, the
object’s size is still 1 (or more) as
before; only when S is used as base
class of another class does its memory
footprint shrink to zero. To realize
the impact of this saving, imagine a
vector that contains 125,000
objects. The EBO alone saves half a
megabyte of memory!

Does it mean that if we don’t use "S" as base class of "T", we would necessarily consume double of megabyte of memory? I think, the article compares two different scenarios which I don’t think is correct.

I would like to know a real scenario when EBO can proven to be useful.(means, in the same scenario, we would necessarily be at loss IF we don’t use EBO!).

Please note that if your answer contains explanations like this :

The whole point is that an empty class has non-zero size, but when derived or deriving it can have zero size, then I’m NOT asking that, as I know that already. My question is, why would anyone derive his class from an empty class in the first place? Even if he doesn’t derive and simply writes his class (without any empty base), is he at loss in ANY way?

  • 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-18T10:13:53+00:00Added an answer on May 18, 2026 at 10:13 am

    EBO is important in the context of policy based design, where you generally inherit privately from multiple policy classes. If we take the example of a thread safety policy, one could imagine the pseudo-code :

    class MTSafePolicy
    {
    public:
      void lock() { mutex_.lock(); }
      void unlock() { mutex_.unlock(); }
    
    private:
      Mutex mutex_;
    };
    
    class MTUnsafePolicy
    {
    public:
      void lock() { /* no-op */ }
      void unlock() { /* no-op */ }
    };
    

    Given a policy based-design class such as :

    template<class ThreadSafetyPolicy>
    class Test : ThreadSafetyPolicy
    {
      /* ... */
    };
    

    Using the class with a MTUnsafePolicy simply add no size overhead the class Test : it’s a perfect example of don’t pay for what you don’t use.

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

Sidebar

Related Questions

After reading about the problem of passing empty std::string objects between DLLs and EXEs,
Reading about the G.729 codec , I found this interesting tidbit about Comfort Noise
When reading about SQL Injection and XSS i was wondering if you guys have
I am reading about COFF file formats, which is commonly used to create an
I was reading about output buffering in JavaScript here , and was trying to
I keep reading about C99 and C++11 and all these totally sweet things that
I've been reading about the new developer-only RC0 for Silverlight, and the fact that
I keep reading about people who are test infected, meaning that they don't just
I keep reading about how great this new Canvas element for HTML5 is and
I've been reading about UpdateFrom, used to update a business object from the request.

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.