C++ C++;虚拟析构函数ROM的使用
我试图理解为什么要用这么多代码来创建一个带有虚拟析构函数的基类。 我正准备写一个在MCU上的小ROM空间的项目,所以它困扰了我很多C++ C++;虚拟析构函数ROM的使用,c++,oop,stm32,mcu,C++,Oop,Stm32,Mcu,我试图理解为什么要用这么多代码来创建一个带有虚拟析构函数的基类。 我正准备写一个在MCU上的小ROM空间的项目,所以它困扰了我很多 #include "stm32g0xx.h" #include "stm32g0xx_nucleo.h" class test { uint32_t data; public: test(): data(0) { } ~test() { } uint32_t
#include "stm32g0xx.h"
#include "stm32g0xx_nucleo.h"
class test
{
uint32_t data;
public:
test(): data(0)
{
}
~test()
{
}
uint32_t getData() const
{
return data;
}
void setData(uint32_t d)
{
data = d;
}
};
int main(void)
{
test t;
for(;;);
}
创建虚拟析构函数需要2k的.text和1k的.data内存。。。为什么?有可能避免使用虚拟析构函数而仍然编写安全的OOP程序吗?为什么你要问我们你的对象文件中有什么,而不是自己分解并查看它?@Adrian你使用哪个命令来获取这些信息—“文本、数据、bss、衰退、十六进制”@gauravbharadwaj arm none eabi size“Destructors.elf”你能检查一下内存使用量是如何随着对象数量的增加而增加的吗?尝试使用更多类型为
test
的对象,也可以使用不同类别的一些对象test2
。还可以尝试不同的优化设置。
text data bss dec hex filename
936 1096 1096 3128 c38 Destructors.elf
#include "stm32g0xx.h"
#include "stm32g0xx_nucleo.h"
class test
{
uint32_t data;
public:
test(): data(0)
{
}
virtual ~test()
{
}
uint32_t getData() const
{
return data;
}
void setData(uint32_t d)
{
data = d;
}
};
int main(void)
{
test t;
for(;;);
}
text data bss dec hex filename
3256 2144 1160 6560 19a0 Destructors.elf