为什么空基类优化不工作? [英] Why empty base class optimization is not working?

查看:149
本文介绍了为什么空基类优化不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么空的基类优化(EBO)在Visual C ++中没有完全应用?

Why is the empty base class optimization (EBO) not being fully applied in Visual C++?

如果我有很多基类,我帮助编译器进行此优化?

If I have a lot of base classes, is there any way for me to help the compiler make this optimization?

#include <iostream>

struct T1 { };
struct T2 { };
struct T3 { };
struct T4 { };
struct T5 { };
struct T6 { };

struct Test : T1, T2, T3, T4, T5, T6 { };

int main() { std::cout << sizeof(Test); }   // Prints 5


推荐答案

Visual C ++编译器。当一个类从多个空基类派生时,只有初始的空基类将使用空基本优化(EBO)进行优化。

This is a longstanding bug in the Visual C++ compiler. When a class derives from multiple empty base classes, only the initial empty base class will be optimized using the empty base optimization (EBO).

在2006年:空基本优化无法正常工作。目前,在Microsoft Connect上看不到旧错误。我被告知这是一个临时问题,虽然我不知道什么时候会解决。同时,以下是对来自Jonathan Caves的bug的回应,Jonathan Caves是Visual C ++编译器团队的开发人员之一:

This issue was reported on Microsoft Connect in 2006: Empty Base Optimization Not Working Properly. At the moment, old bugs are not visible on Microsoft Connect. I am told that this is a temporary issue, though I do not know when it will be resolved. In the meantime, the following is the response to the bug from Jonathan Caves, who is one of the developers on the Visual C++ compiler team:


Hi:不幸的是,即使这是Visual C ++对象模型中的一个错误,我们无法修复它在这个时候,修复它可能会打破很多现有的程序,因为对象的大小会改变。希望在未来我们可以解决这个问题,但不是为下一版本的产品。

Hi: unfortunately even though this is a bug in the Visual C++ object model we are unable to fix it at this time given that fixing it would potentially break a lot of existing programs as the sizes of objects would change. Hopefully in the future we may be able to address this issue but not for the next release of the product.

感谢您报告问题。

这篇关于为什么空基类优化不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆