在C++中使用设置容器是否使用课程需要释放内存?
class rfdevice_ams2_l9s_cn_qm13341_sub_MIPI_data_ag:public rfdevice_asm2_data
{
public:
static rfdevice_asm2_data * get_instance();
***std::set<int> Band_Count;***
bool THCH_NRCA = false;
bool THCH_ENDC = false;
bool THCH_LTE_LTECA = false;
bool THCH_GSM = false;
bool THCH_WCDMA = false;
bool THCH_CDMA = false;
int Band_res;
void Count_Band(rfdevice_asm2_tuning_data_info *tuning_data, int ant_cur, uint8 scenario);
void port_cc();
boolean Get_NR_NRCA(rfdevice_asm2_tuning_data_info *tuning_data, uint8 *port, uint8 scenario);
boolean Get_LTE_SIGNLE(rfdevice_asm2_tuning_data_info *tuning_data, uint8 *port, uint8 scenario);
void TECH_Judge(rfdevice_asm2_tuning_data_info *tuning_data, uint8 scenario);
boolean port_cc(rfdevice_asm2_tuning_data_info *tuning_data, uint8 *port, uint8 scenario);
boolean get_script(rfdevice_asm2_cfg_params_type *cfg, rfdevice_asm2_settings_type_u *settings);
~rfdevice_ams2_l9s_cn_qm13341_sub_MIPI_data_ag(void); /* Destructor */
protected:
rfdevice_ams2_l9s_cn_qm13341_sub_MIPI_data_ag(void); /* Constructor */
private:
static rfdevice_asm2_data *rfdevice_ams2_l9s_cn_qm13341_sub_data_ptr;
};
C ++类中的设置容器的使用是否需要发布内存? 例如,std :: set band_count在此处;我需要在破坏者中释放内存吗?
class rfdevice_ams2_l9s_cn_qm13341_sub_MIPI_data_ag:public rfdevice_asm2_data
{
public:
static rfdevice_asm2_data * get_instance();
***std::set<int> Band_Count;***
bool THCH_NRCA = false;
bool THCH_ENDC = false;
bool THCH_LTE_LTECA = false;
bool THCH_GSM = false;
bool THCH_WCDMA = false;
bool THCH_CDMA = false;
int Band_res;
void Count_Band(rfdevice_asm2_tuning_data_info *tuning_data, int ant_cur, uint8 scenario);
void port_cc();
boolean Get_NR_NRCA(rfdevice_asm2_tuning_data_info *tuning_data, uint8 *port, uint8 scenario);
boolean Get_LTE_SIGNLE(rfdevice_asm2_tuning_data_info *tuning_data, uint8 *port, uint8 scenario);
void TECH_Judge(rfdevice_asm2_tuning_data_info *tuning_data, uint8 scenario);
boolean port_cc(rfdevice_asm2_tuning_data_info *tuning_data, uint8 *port, uint8 scenario);
boolean get_script(rfdevice_asm2_cfg_params_type *cfg, rfdevice_asm2_settings_type_u *settings);
~rfdevice_ams2_l9s_cn_qm13341_sub_MIPI_data_ag(void); /* Destructor */
protected:
rfdevice_ams2_l9s_cn_qm13341_sub_MIPI_data_ag(void); /* Constructor */
private:
static rfdevice_asm2_data *rfdevice_ams2_l9s_cn_qm13341_sub_data_ptr;
};
Does the use of set containers in c++ classes need to release memory?
For example, std::set Band_Count in here;Do I need to release memory in the destructor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
C ++具有破坏者,应该清除所有内存。对于C ++库中的(模板)类,总是如此。
呼叫
set :: clear()
在驱动器运行之前是一种从集合中删除所有对象的方法,从而释放用于包含对象的内存。set :: size()
之后为零。这确实意味着仍然需要一个非常非常的非常记忆,以记录一个零元素的事实。少量的簿记是sizeof(std :: set&lt; int&gt;)
。std :: set&lt; yourClass&gt; :: clear()
将调用yourClass
的击路仪,以便收回内存。但是int
没有破坏者(不是类),因此std :: set&lt; :: clear()
更简单。C++ has destructors, which should clear all memory. For the (template) classes in the C++ library, that's always the case.
Calling
set::clear()
before the destructor runs is a way to remove all objects from the set, releasing the memory used for the contained objects.set::size()
will be zero afterwards. That does mean there is a very, very small amount of memory still needed, to record the fact that there are zero elements. This small amount of bookkeeping issizeof(std::set<int>)
.std::set<YourClass>::clear()
will call the destructors ofYourClass
, so that memory too is reclaimed. Butint
has no destructors (it's not a class) sostd::set<int>::clear()
is a bit simpler.