C ++对象的最大字段数 [英] Maximum number of fields for a C++ object

查看:128
本文介绍了C ++对象的最大字段数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

回答说,在Java中,对象可能具有的最大字段数为65536。

This answer states that in Java the maximum number of fields an object may have is 65536.

在C ++中对对象是否有这样的限制?

Is there any such limit imposed on an object in C++?

推荐答案

C ++ 03标准,附件B(实施数量):

C++03 standard, Annex B (implementation quantities):



  1. 因为计算机是有限的,C ++实现不可避免地限制了
    在它们可以
    成功处理的程序的大小。每个
    实施应记录那些已知的
    限制。这个
    文档可以引用固定的限制
    ,如果它们存在,说如何计算
    变量限制作为
    可用资源的函数,或者说固定的
    限制

  1. Because computers are finite, C++ implementations are inevitably limited in the size of the programs they can successfully process. Every implementation shall document those limitations where known. This documentation may cite fixed limits where they exist, say how to compute variable limits as a function of available resources, or say that fixed limits do not exist or are unknown.

这些限制可能会限制数量
,包括下面描述的数额或
others。每个数量
后面的括号中的数字被推荐为该数量的
最小值。但是,
这些数量只是指导原则
,不能确定合规性。

The limits may constrain quantities that include those described below or others. The bracketed number following each quantity is recommended as the minimum for that quantity. However, these quantities are only guidelines and do not determine compliance.



b $ b

列表包括

The list includes


  • 对象的大小[262 144]。

  • 单个类,结构或联合中的数据成员[16 384]。

  • 在单个类中声明的成员[4 096]。

因此,没有定义的限制,但是应用限制应该的实现使限制至少与指示的值一样大。恐怕我不知道什么常见的实现实际上做,但如果他们不记录它,他们是不符合,否则极限是未知。我想未知通常意味着我们可以在编译时适合的可用内存。

So there's no defined limit, but an implementation which applies a limit "should" make the limit at least as big as the value indicated. I'm afraid I don't know what common implementations actually do, but if they don't document it they're either not compliant, or else the limit is "unknown". I guess that "unknown" generally means, "as many as we can fit in the available memory at compile time".

Btw,我不知道什么区别在类中的成员和在类中声明的成员之间。我认为这意味着如果你的基类有10个数据成员,并且你的类声明了10个成员,那么你的类总共有20(或21)个数据成员(取决于基类子对象是否作为数据成员计数) )。

Btw, I'm not sure what the difference is between "members in a class" and "members declared in a class". I think it means that if your base class has 10 data members, and your class declares 10 members, then your class has 20 (or 21) data members in total (depending whether the base class sub-object counts as a data member or not).

这篇关于C ++对象的最大字段数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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