为什么空基类优化(EBO)在MSVC中不起作用? [英] Why is the empty base class optimization (EBO) is not working in MSVC?

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

问题描述

为什么空基类优化(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上报告了此问题:

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:

嗨:不幸的是,即使这是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.

感谢您报告问题.

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

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