什么是“几乎为空”?类? [英] What is a "nearly-empty" class?
本文介绍了什么是“几乎为空”?类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
编译以下类
class Interface
{
virtual void doIt() = 0;
virtual ~Interface() = 0;
};
inline Interface::~Interface() {}
使用 gcc -fdump-class-hierarchy
。
gcc
发出
Class Interface
size=4 align=4
base size=4 base align=4
Interface (0x1a779c0) 0 nearly-empty
vptr=((& Interface::_ZTV9Interface) + 8u)
含义是什么几乎是空的?
What is the significance of "nearly-empty"? What does it mean?
推荐答案
C ++ ABI 提供了近空类的定义,并有趣地讨论了它们如何影响vtable的构建:
The C++ ABI provides a definition of "nearly empty" classes and an interesting discussion of how they affect vtable construction:
一个类,它包含一个虚拟指针,但除了(可能)虚拟基数以外,没有其他数据。特别是,它:
A class that contains a virtual pointer, but no other data except (possibly) virtual bases. In particular, it:
- 除了零宽度位域,没有其他非静态数据成员,
- 没有不为空,几乎为空或为虚拟的直接基类,
- 最多具有一个非虚拟,几乎为空的直接基类,并且
- 没有合适的基类,该基类为空,不是道德虚拟的,并且偏移量不是零。
- has no non-static data members other than zero-width bitfields,
- has no direct base classes that are not either empty, nearly empty, or virtual,
- has at most one non-virtual, nearly empty direct base class, and
- has no proper base class that is empty, not morally virtual, and at an offset other than zero.
我在研究几乎空的虚拟基数对对象大小,vtable大小和虚拟调用开销的影响时遇到了这个问题。
I ran across this while researching the effect of nearly empty virtual bases on object size, vtable size, and virtual call overhead.
这篇关于什么是“几乎为空”?类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文