This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] 编译器/TM4C129CNCZAD:内存中的类大小似乎过大

Guru**** 655270 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/653941/compiler-tm4c129cnczad-size-of-class-in-memory-seems-too-large

部件号:TM4C129CNCZAD

工具/软件:TI C/C++编译器

我有一个课程如下所示:

template<typename T>
class ParameterCheck {
public:
ParameterCheck(volatile T* parameter_ptr,T init_value):
last_value_(init_value),
PARAMETER_PTR_(PARAMETER_PTR){};

布尔DidChange (void){
如果(Last_value_!=*Parameter_PTR_){
Last_value_=*参数_PTR_;
返回true;
}
返回false;
}
private:
T last_value_;
volatile T* parameter_PTR_;
}; 

在函数中,创建此类的数组,如下所示:

静态参数检查<Int32_t> i32_parameters[]={
ParameterCheck<Int32_t>(&parameter1,0),
ParameterCheck<Int32_t>(&parameter2,0),
ParameterCheck<Int32_t>(&parameter3,0),
ParameterCheck<Int32_t>(&parameter4,0),
ParameterCheck<Int32_t>(&parameter5,0),
ParameterCheck<Int32_t>(&parameter6,0)
,};


静态参数检查<uint64_t> u64_parameters[]={
参数检查<uint64_t>(&parameter7,0ULL),
参数检查<uint64_t>(&}8,0ULL)参数
; 

当我编译该文件并检查映射文件中这些结构的大小时,i32_parameters解析为48,这意味着每个元素为8字节。  这就是我对一个在32位处理器上有in32_t和指针的类的期望。  但是,当我检查u64_parameters的大小时,它会报告32,表示每个元素为16字节。  它应该是4 + 8 = 12字节。  如果我使用u64_parameters 3而不是2个元素,则得到相同的结果。  为什么编译器在此处添加额外的4个字节?  是否有一些我没有考虑的调整?  我知道编译器应该满足4的内存宽度,但12是4的倍数。  是否有人对这种情况可能发生的原因有任何见解?